aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-11-28 11:56:29 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-11-28 15:23:25 -0800
commit30f7c59e9010ccdfa601f28e22fd4e449f266df1 (patch)
treeaa7d9bd5c196760c5c097192c526c8cd8952aeef /activerecord/lib
parentffb218c750a876758f92e04a96a0676c77943208 (diff)
downloadrails-30f7c59e9010ccdfa601f28e22fd4e449f266df1.tar.gz
rails-30f7c59e9010ccdfa601f28e22fd4e449f266df1.tar.bz2
rails-30f7c59e9010ccdfa601f28e22fd4e449f266df1.zip
clean up string => hash conversion for connection pool
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb36
1 files changed, 17 insertions, 19 deletions
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: