Created
August 2, 2012 19:02
-
-
Save elevine/3239782 to your computer and use it in GitHub Desktop.
ActiveRecord establish_connection
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
| #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