Created
March 28, 2012 12:32
-
-
Save savonarola/2225806 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Models | |
module Connections | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :using_database, :_database_config | |
end | |
module ClassMethods | |
def database_config=(config) | |
_database_config = config.to_hash if config.respond_to(:to_hash) | |
end | |
def using(dbname, &block) | |
return unless block_given? | |
establish_connection(_database_config[dbname]) | |
self.using_database = dbname | |
yield(self) | |
self.using_database = Rails.env | |
establish_connection(Rails.env) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment