diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2013-12-24 10:18:54 +0100 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2013-12-24 10:18:54 +0100 |
commit | ec11807368318845a2542e8f5f51f3f5280135f5 (patch) | |
tree | 352a376a8ae1461ebd86b3206d4792a508c853ee /activerecord/lib/active_record/connection_adapters | |
parent | d2ed433b0af948da78e971bf342c506b27f6072f (diff) | |
download | rails-ec11807368318845a2542e8f5f51f3f5280135f5.tar.gz rails-ec11807368318845a2542e8f5f51f3f5280135f5.tar.bz2 rails-ec11807368318845a2542e8f5f51f3f5280135f5.zip |
Deprecate use of string in establish_connection as connection lookup
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/connection_specification.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index a3c645c53c..7e16156408 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -26,7 +26,7 @@ module ActiveRecord if config resolve_connection config elsif defined?(Rails.env) - resolve_env_connection Rails.env + resolve_env_connection Rails.env.to_sym else raise AdapterNotSpecified end @@ -55,7 +55,7 @@ module ActiveRecord def resolve_connection(spec) #:nodoc: case spec when Symbol, String - resolve_env_connection spec.to_s + resolve_env_connection spec when Hash resolve_hash_connection spec end @@ -63,14 +63,21 @@ module ActiveRecord def resolve_env_connection(spec) # :nodoc: # Rails has historically accepted a string to mean either - # an environment key or a url spec. So we support both for - # now but it would be nice to limit the environment key only - # for symbols. - config = configurations.fetch(spec.to_s) do - resolve_string_connection(spec) if spec.is_a?(String) + # an environment key or a url spec, so we have deprecated + # this ambiguous behaviour and in the future this function + # can be removed in favor of resolve_string_connection and + # resolve_symbol_connection. + if config = configurations[spec.to_s] + if spec.is_a?(String) + ActiveSupport::Deprecation.warn "Passing a string to ActiveRecord::Base.establish_connection " \ + "for a configuration lookup is deprecated, please pass a symbol (#{spec.to_sym.inspect}) instead" + end + resolve_connection(config) + elsif spec.is_a?(String) + resolve_string_connection(spec) + else + raise(AdapterNotSpecified, "#{spec} database is not configured") end - raise(AdapterNotSpecified, "#{spec} database is not configured") unless config - resolve_connection(config) end def resolve_hash_connection(spec) # :nodoc: |