Created
July 22, 2009 21:30
-
-
Save ddeaguiar/152293 to your computer and use it in GitHub Desktop.
This file contains 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
def self.establish_connection(spec = nil) | |
case spec | |
when nil | |
raise AdapterNotSpecified unless defined? RAILS_ENV | |
establish_connection(RAILS_ENV) | |
when ConnectionSpecification | |
@@connection_handler.establish_connection(name, spec) | |
when Symbol, String | |
if configuration = configurations[spec.to_s] || configuration = configurations[Rails.env][spec.to_s] | |
establish_connection(configuration) | |
else | |
raise AdapterNotSpecified, "#{spec} database is not configured" | |
end | |
else | |
spec = spec['default'] ? spec['default'].symbolize_keys : spec.symbolize_keys | |
unless spec.key?(:adapter) then raise AdapterNotSpecified, "database configuration does not specify adapter" end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment