Skip to content

Instantly share code, notes, and snippets.

@elevine
Created August 2, 2012 19:02
Show Gist options
  • Save elevine/3239782 to your computer and use it in GitHub Desktop.
Save elevine/3239782 to your computer and use it in GitHub Desktop.
ActiveRecord establish_connection
#from module ConnectionHandling
def establish_connection(spec = ENV["DATABASE_URL"])
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new spec, configurations
spec = resolver.spec
unless respond_to?(spec.adapter_method)
raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
end
remove_connection
connection_handler.establish_connection name, spec
end
#which calls....
def remove_connection(klass = self)
connection_handler.remove_connection(klass)
end
#connection handler is a ConnectionPool fron connection_pool.rb
def remove_connection(klass)
pool = class_to_pool.delete(klass.name)
return nil unless pool
connection_pools.delete pool.spec
pool.automatic_reconnect = false
pool.disconnect!
pool.spec.config
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment