aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorJordan Brough <git.j@brgh.net>2017-12-13 12:46:42 -0700
committerJordan Brough <git.j@brgh.net>2017-12-13 13:18:03 -0700
commit9adaf605b4fb0075855c062c30fa4fdd96927b93 (patch)
tree96f653e61080472c624911c0e04575e8a52be69a /activesupport/lib
parentbf4ee05a1b948b76ad76a450a41376804dde57ba (diff)
downloadrails-9adaf605b4fb0075855c062c30fa4fdd96927b93.tar.gz
rails-9adaf605b4fb0075855c062c30fa4fdd96927b93.tar.bz2
rails-9adaf605b4fb0075855c062c30fa4fdd96927b93.zip
Preserve original method visibility when deprecating a method
This commit fixes `deprecate` so that it preserves method visibility (like it did previously when it was utilizing `alias_method_chain`). When Module#prepend replaced alias_method_chain in a982a42 it caused deprecated methods to always become public. `alias_method_chain` had this bit of code: https://github.com/rails/rails/blob/v5.0.6/activesupport/lib/active_support/core_ext/module/aliasing.rb#L40-L47 which preserved method visibility. Without this fix, a workaround would be: ```ruby class C8 private def new_method end def old_method end deprecate :old_method, :new_method # workaround: instance_method(:old_method).owner.send(:private, :old_method) end ``` Because the visibility needs to be fixed on the Module prepended by MethodWrapper.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/deprecation/method_wrappers.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb
index c4b78102eb..5be893d281 100644
--- a/activesupport/lib/active_support/deprecation/method_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb
@@ -60,6 +60,13 @@ module ActiveSupport
deprecator.deprecation_warning(method_name, options[method_name])
super(*args, &block)
end
+
+ case
+ when target_module.protected_method_defined?(method_name)
+ protected method_name
+ when target_module.private_method_defined?(method_name)
+ private method_name
+ end
end
end