aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-10-31 12:02:22 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-10-31 12:04:20 +0900
commitb86c2a6767b939c420687db7df078625c702dc7a (patch)
treef3e78c5b2140cc5140772c487ba649cc5bd76983 /activerecord
parentabda6fc3e82b373b537d69f4a1ca6b55439ca360 (diff)
downloadrails-b86c2a6767b939c420687db7df078625c702dc7a.tar.gz
rails-b86c2a6767b939c420687db7df078625c702dc7a.tar.bz2
rails-b86c2a6767b939c420687db7df078625c702dc7a.zip
Fix "warning: shadowing outer local variable - role"
Caused at #34196.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_handling.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb
index e3b59b8a22..777cb8a402 100644
--- a/activerecord/lib/active_record/connection_handling.rb
+++ b/activerecord/lib/active_record/connection_handling.rb
@@ -109,15 +109,19 @@ module ActiveRecord
if database && role
raise ArgumentError, "connected_to can only accept a database or role argument, but not both arguments."
elsif database
- database = { database => database } if database.is_a?(Symbol)
- database.each do |role, database_key|
- config_hash = resolve_config_for_connection(database_key)
- handler = lookup_connection_handler(role.to_sym)
-
- with_handler(role.to_sym) do
- handler.establish_connection(config_hash)
- return yield
- end
+ if database.is_a?(Hash)
+ role, database = database.first
+ role = role.to_sym
+ else
+ role = database.to_sym
+ end
+
+ config_hash = resolve_config_for_connection(database)
+ handler = lookup_connection_handler(role)
+
+ with_handler(role) do
+ handler.establish_connection(config_hash)
+ yield
end
elsif role
with_handler(role.to_sym, &blk)