2
votes

In this question is explained what to do to make a simple warning (but do not log trace so is not so useful) and there is a bunch of methods to make this, but I found no guides.

How do I use ActiveSupport::Deprecation to mark a old_method as deprecated and call other new_method.

2

2 Answers

0
votes

You may want to look into lib/active_support/deprecation/method_wrappers.rb for an example.

0
votes

As Roman says, it can be done with ActiveSupport::Deprecation.deprecate_methods(target_module, *deprecated_methods)

where:

  • target_module is the module or class where the method belongs.
  • deprecated_methods is an array of symbols.

In the last methods can be given options to customize the deprecation message.

ActiveSupport::Deprecation.deprecate_methods(target_module, :old_method, \
    :other_old_method => :new_method, :another_old_method => "custom message")

This example shows the default message when old_method is called, give a comment to "use new_method instead", in the second one, and the custom message with :another_old_method.

Notes: The deprecated methods should be defined (before) and will be executed. The :new_method is not called automatically. (there are more options, but I don't know them)