From 779ccf8a0e6a8bf7bb362c30dac4a340599ab113 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Tue, 24 May 2016 23:57:43 -0400 Subject: Remove `name` from `establish_connection` Instead of passing a separete name variable, we can make the resolver merge a name on the config, and use that before creating the Specification. --- .../connection_adapters/connection_specification.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/connection_specification.rb') diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index 7636de067c..0f4bd1c84a 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -164,7 +164,7 @@ module ActiveRecord # spec.config # # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" } # - def spec(config, name = nil) + def spec(config) spec = resolve(config).symbolize_keys raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter) @@ -184,13 +184,7 @@ module ActiveRecord raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter" end - name ||= - if config.is_a?(Symbol) - config.to_s - else - "primary" - end - ConnectionSpecification.new(name, spec, adapter_method) + ConnectionSpecification.new(spec.delete(:name) || "primary", spec, adapter_method) end private @@ -235,7 +229,7 @@ module ActiveRecord # def resolve_symbol_connection(spec) if config = configurations[spec.to_s] - resolve_connection(config) + resolve_connection(config).merge("name" => spec.to_s) else raise(AdapterNotSpecified, "'#{spec}' database is not configured. Available: #{configurations.keys.inspect}") end -- cgit v1.2.3