Skip to content

Instantly share code, notes, and snippets.

@ddeaguiar
Created July 22, 2009 21:30
Show Gist options
  • Save ddeaguiar/152293 to your computer and use it in GitHub Desktop.
Save ddeaguiar/152293 to your computer and use it in GitHub Desktop.
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