Hi all
I'm busy writing a gem that uses ActiveRecord to access a legacy database, and will be used on its own and as a part of Rails applications. The gem on its own works pretty well so far, but I hit some snags whilst implementing it into a Rails app for the first time.
I followed what I though would be a safe path to multi-connection bliss, briefly summarized here:
module ActiveRecord class Legacy < Base self.abstract_class = true end end
Then during the project initialization I set ActiveRecord::Legacy.configurations from another yml file, and this overwrites ActiveRecord::Base.configurations.
I'm pretty well aware that I can connect each model separately to the legacy database by using ActiveRecord::Legacy.establish_connection (which is currently what I'm doing). But this is not very DRY. I'm moving over to using ActiveRecord::Legacy.inherited as a hack to connect each legacy model, but its still ugly.
Wouldn't changing ActiveRecord::Base.configurations from a cattr_accessor to class_inheritable_accessor solve this problem while remaining backward compatible and being more open for multi-database connections? If each model can have their own database connection, surely they can have their database configuration as well?
Making a local change now and running all the tests to check what the impact is, just though I'll put the idea out there in the meantime.
Best