2

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.

Community
  • 1
  • 1
eloyesp
  • 3,135
  • 1
  • 32
  • 47

2 Answers2

0

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

Roman
  • 13,100
  • 2
  • 47
  • 63
  • What do you mean? This is a file which shows, how Rails' uses deprecation. In essence, what you need in your code, is to call ActiveSupport::Deprecation.deprecate_methods(target_module, *method_names), and that's it. – Roman May 18 '11 at 06:51
  • this file don't explain how to to give options, i realized that if i use `ActiveSupport::Deprecation.deprecate_methods(target_module, :deprecated_method => :new_method)` It use new method in the message given. There are other options, but they are not well documented. Thanks. – eloyesp May 20 '11 at 11:36
0

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)

Community
  • 1
  • 1
eloyesp
  • 3,135
  • 1
  • 32
  • 47