aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/deprecation
diff options
context:
space:
mode:
authorBrandon Dunne <bdunne@redhat.com>2015-10-13 14:10:14 -0400
committerBrandon Dunne <bdunne@redhat.com>2015-10-14 07:49:39 -0400
commit6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8 (patch)
treec1cc494cb2b4a3c7fb62f275b84f8a6b0f96f468 /activesupport/lib/active_support/deprecation
parent31af8c90b60dc475fd80d2919bfb874b4acc4507 (diff)
downloadrails-6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8.tar.gz
rails-6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8.tar.bz2
rails-6c98fbd9c3cc28ccbfc1b46a9ce3d58fdb19f3c8.zip
Fix bug where custom deprecators are not used.
Add tests for ActiveSupport::Deprecation.deprecate_methods Modify ActiveSupport::Testing::Deprecation to allow a custom deprecator Leverage ActiveSupport::Testing::Deprecation assert_deprecated Update documentation for ActiveSupport::Deprecation.deprecate_methods Use cases: Using the default deprecator => "removed from Rails X.Y" Passing a custom deprecator in the options hash => "removed from MyGem next-release" Deprecating methods directly from custom deprecator => "removed from MyGem next-release"
Diffstat (limited to 'activesupport/lib/active_support/deprecation')
-rw-r--r--activesupport/lib/active_support/deprecation/method_wrappers.rb48
1 files changed, 36 insertions, 12 deletions
diff --git a/activesupport/lib/active_support/deprecation/method_wrappers.rb b/activesupport/lib/active_support/deprecation/method_wrappers.rb
index 91050d18f0..32fe8025fe 100644
--- a/activesupport/lib/active_support/deprecation/method_wrappers.rb
+++ b/activesupport/lib/active_support/deprecation/method_wrappers.rb
@@ -9,25 +9,49 @@ module ActiveSupport
# module Fred
# extend self
#
- # def foo; end
- # def bar; end
- # def baz; end
+ # def aaa; end
+ # def bbb; end
+ # def ccc; end
+ # def ddd; end
+ # def eee; end
# end
#
- # ActiveSupport::Deprecation.deprecate_methods(Fred, :foo, bar: :qux, baz: 'use Bar#baz instead')
- # # => [:foo, :bar, :baz]
+ # Using the default deprecator:
+ # ActiveSupport::Deprecation.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
+ # # => [:aaa, :bbb, :ccc]
#
- # Fred.foo
- # # => "DEPRECATION WARNING: foo is deprecated and will be removed from Rails 4.1."
+ # Fred.aaa
+ # # DEPRECATION WARNING: aaa is deprecated and will be removed from Rails 5.0. (called from irb_binding at (irb):10)
+ # # => nil
#
- # Fred.bar
- # # => "DEPRECATION WARNING: bar is deprecated and will be removed from Rails 4.1 (use qux instead)."
+ # Fred.bbb
+ # # DEPRECATION WARNING: bbb is deprecated and will be removed from Rails 5.0 (use zzz instead). (called from irb_binding at (irb):11)
+ # # => nil
#
- # Fred.baz
- # # => "DEPRECATION WARNING: baz is deprecated and will be removed from Rails 4.1 (use Bar#baz instead)."
+ # Fred.ccc
+ # # DEPRECATION WARNING: ccc is deprecated and will be removed from Rails 5.0 (use Bar#ccc instead). (called from irb_binding at (irb):12)
+ # # => nil
+ #
+ # Passing in a custom deprecator:
+ # custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
+ # ActiveSupport::Deprecation.deprecate_methods(Fred, ddd: :zzz, deprecator: custom_deprecator)
+ # # => [:ddd]
+ #
+ # Fred.ddd
+ # DEPRECATION WARNING: ddd is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):15)
+ # # => nil
+ #
+ # Using a custom deprecator directly:
+ # custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
+ # custom_deprecator.deprecate_methods(Fred, eee: :zzz)
+ # # => [:eee]
+ #
+ # Fred.eee
+ # DEPRECATION WARNING: eee is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):18)
+ # # => nil
def deprecate_methods(target_module, *method_names)
options = method_names.extract_options!
- deprecator = options.delete(:deprecator) || ActiveSupport::Deprecation.instance
+ deprecator = options.delete(:deprecator) || self
method_names += options.keys
mod = Module.new do