diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2019-02-11 15:05:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-11 15:05:55 -0500 |
commit | f9e68198516ac6c43a5b583d049d76a466951126 (patch) | |
tree | c5caa134b8060cf8a987325cedc9a7b4767eb512 /railties/lib/rails | |
parent | 05232f3f8026103d0387ead54e537b5027ee7389 (diff) | |
parent | de96628c76f88e0cbd891f4342bb1b3277339831 (diff) | |
download | rails-f9e68198516ac6c43a5b583d049d76a466951126.tar.gz rails-f9e68198516ac6c43a5b583d049d76a466951126.tar.bz2 rails-f9e68198516ac6c43a5b583d049d76a466951126.zip |
Merge pull request #35198 from paracycle/uk-change-config-for-behaviour
Allow deprecated non-symbol access to nested `config_for` hashes
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/application.rb | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 5a924ab8e6..d0417f8a49 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -7,6 +7,7 @@ require "active_support/key_generator" require "active_support/message_verifier" require "active_support/encrypted_configuration" require "active_support/deprecation" +require "active_support/hash_with_indifferent_access" require "rails/engine" require "rails/secrets" @@ -230,8 +231,8 @@ module Rails config = YAML.load(ERB.new(yaml.read).result) || {} config = (config["shared"] || {}).merge(config[env] || {}) - ActiveSupport::OrderedOptions.new.tap do |config_as_ordered_options| - config_as_ordered_options.update(config.deep_symbolize_keys) + ActiveSupport::OrderedOptions.new.tap do |options| + options.update(NonSymbolAccessDeprecatedHash.new(config)) end else raise "Could not load configuration. No such file - #{yaml}" @@ -590,5 +591,38 @@ module Rails def build_middleware config.app_middleware + super end + + class NonSymbolAccessDeprecatedHash < HashWithIndifferentAccess # :nodoc: + def initialize(value = nil) + if value.is_a?(Hash) + value.each_pair { |k, v| self[k] = v } + else + super + end + end + + def []=(key, value) + if value.is_a?(Hash) + value = self.class.new(value) + end + super(key.to_sym, value) + end + + private + + def convert_key(key) + unless key.kind_of?(Symbol) + ActiveSupport::Deprecation.warn(<<~MESSAGE.squish) + Accessing hashes returned from config_for by non-symbol keys + is deprecated and will be removed in Rails 6.1. + Use symbols for access instead. + MESSAGE + + key = key.to_sym + end + + key + end + end end end |