Skip to content

Instantly share code, notes, and snippets.

@savonarola
Created March 28, 2012 12:32
Show Gist options
  • Save savonarola/2225806 to your computer and use it in GitHub Desktop.
Save savonarola/2225806 to your computer and use it in GitHub Desktop.
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