aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/deprecation.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/deprecation.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/module/deprecation.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/module/deprecation.rb b/activesupport/lib/active_support/core_ext/module/deprecation.rb
index 9e77ac3c45..9affd38baa 100644
--- a/activesupport/lib/active_support/core_ext/module/deprecation.rb
+++ b/activesupport/lib/active_support/core_ext/module/deprecation.rb
@@ -1,10 +1,42 @@
require 'active_support/deprecation/method_wrappers'
class Module
- # Declare that a method has been deprecated.
# deprecate :foo
# deprecate :bar => 'message'
# deprecate :foo, :bar, :baz => 'warning!', :qux => 'gone!'
+ #
+ # You can use custom deprecator instance
+ # deprecate :foo, :deprecator => MyLib::Deprecator.new
+ # deprecate :foo, :bar => "warning!", :deprecator => MyLib::Deprecator.new
+ #
+ # \Custom deprecators must respond to one method
+ # [deprecation_warning(deprecated_method_name, message, caller_backtrace)] will be called with the deprecated
+ # method name, the message it was declared
+ # with and caller_backtrace. Implement
+ # whatever warning behavior you like here.
+ #
+ # Example
+ # class MyLib::Deprecator
+ #
+ # def deprecation_warning(deprecated_method_name, message, caller_backtrace)
+ # message = "#{method_name} is deprecated and will be removed from MyLibrary | #{message}"
+ # Kernel.warn message
+ # end
+ #
+ # end
+ #
+ # module MyLib
+ # mattr_accessor :deprecator
+ # self.deprecator = Deprecator.new
+ # end
+ #
+ # When we deprecate method
+ # class MyLib::Bar
+ # deprecate :foo => "this is very old method", :deprecator => MyLib.deprecator
+ # end
+ #
+ # It will build deprecation message and invoke deprecator warning by calling
+ # MyLib.deprecator.deprecation_warning(:foo, "this is a very old method", caller)
def deprecate(*method_names)
ActiveSupport::Deprecation.deprecate_methods(self, *method_names)
end