diff options
author | Edouard CHIN <edouard.chin@shopify.com> | 2018-07-10 12:03:54 -0400 |
---|---|---|
committer | Edouard CHIN <edouard.chin@shopify.com> | 2018-07-30 18:12:56 -0400 |
commit | 015477ae9109d4105d5a5057d82338f198febb74 (patch) | |
tree | c491df5cda00133217c5d4d99cd35b2f7f5506e5 /activesupport/lib | |
parent | d4ea114bd611c608482375af94f49e2d54889202 (diff) | |
download | rails-015477ae9109d4105d5a5057d82338f198febb74.tar.gz rails-015477ae9109d4105d5a5057d82338f198febb74.tar.bz2 rails-015477ae9109d4105d5a5057d82338f198febb74.zip |
A regression in deprecate_methods was introduced in a982a42:
- Refactoring alias_chain to Module#prepend broke the possibility to deprecate class methods since the module
generated was prepended to the target's instance.
A suggestion to fix this was to use `AS#redefine_method` which would solve the
problem but with the cost of redefining directly the method.
Decided to go with the same alias_chain implementation as before instead.
- Fixes #33253
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/deprecation/method_wrappers.rb | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb index 5be893d281..468978d610 100644 --- a/activesupport/lib/active_support/deprecation/method_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb @@ -54,23 +54,26 @@ module ActiveSupport deprecator = options.delete(:deprecator) || self method_names += options.keys - mod = Module.new do - method_names.each do |method_name| - define_method(method_name) do |*args, &block| - deprecator.deprecation_warning(method_name, options[method_name]) - super(*args, &block) - end + method_names.each do |method_name| + aliased_method, punctuation = method_name.to_s.sub(/([?!=])$/, ""), $1 + with_method = "#{aliased_method}_with_deprecation#{punctuation}" + without_method = "#{aliased_method}_without_deprecation#{punctuation}" - case - when target_module.protected_method_defined?(method_name) - protected method_name - when target_module.private_method_defined?(method_name) - private method_name - end + target_module.send(:define_method, with_method) do |*args, &block| + deprecator.deprecation_warning(method_name, options[method_name]) + send(without_method, *args, &block) end - end - target_module.prepend(mod) + target_module.send(:alias_method, without_method, method_name) + target_module.send(:alias_method, method_name, with_method) + + case + when target_module.protected_method_defined?(without_method) + target_module.send(:protected, method_name) + when target_module.private_method_defined?(without_method) + target_module.send(:private, method_name) + end + end end end end |