From 30f7c59e9010ccdfa601f28e22fd4e449f266df1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 28 Nov 2011 11:56:29 -0800 Subject: clean up string => hash conversion for connection pool --- .../abstract/connection_specification.rb | 36 ++++++++++------------ 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb index e1f3d40bc3..65570da0d9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb @@ -55,29 +55,27 @@ module ActiveRecord # The exceptions AdapterNotSpecified, AdapterNotFound and ArgumentError # may be returned on an error. def self.establish_connection(spec = ENV["DATABASE_URL"]) - case spec - when nil - raise AdapterNotSpecified unless defined?(Rails.env) - spec = resolve_string_connection Rails.env - when Symbol, String - spec = resolve_string_connection spec.to_s - when Hash - spec = resolve_hash_connection spec - end - - if ConnectionSpecification === spec - return self.connection_handler.establish_connection(name, spec) - end + config = case spec + when nil + raise AdapterNotSpecified unless defined?(Rails.env) + resolve_string_connection Rails.env + when Symbol, String + resolve_string_connection spec.to_s + when Hash + resolve_hash_connection spec + end + + connection_handler.establish_connection(name, config) end def self.resolve_string_connection(spec) # :nodoc: - if configuration = configurations[spec] - spec = resolve_hash_connection(configuration) - elsif hash = connection_url_to_hash(spec) - spec = resolve_hash_connection(hash) - else - raise AdapterNotSpecified, "#{spec} database is not configured" + hash = configurations.fetch(spec) do |k| + connection_url_to_hash(k) end + + raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash + + resolve_hash_connection hash end def self.resolve_hash_connection(spec) # :nodoc: -- cgit v1.2.3