Module: ActiveSupport::Deprecation::MethodWrapper
- Included in:
- ActiveSupport::Deprecation
- Defined in:
- activesupport/lib/active_support/deprecation/method_wrappers.rb
Instance Method Summary collapse
-
#deprecate_methods(target_module, *method_names) ⇒ Object
Declare that a method has been deprecated.
Instance Method Details
#deprecate_methods(target_module, *method_names) ⇒ Object
Declare that a method has been deprecated.
module Fred
extend self
def foo; end
def ; end
def baz; end
end
ActiveSupport::Deprecation.deprecate_methods(Fred, :foo, bar: :qux, baz: 'use Bar#baz instead')
# => [:foo, :bar, :baz]
Fred.foo
# => "DEPRECATION WARNING: foo is deprecated and will be removed from Rails 4.1."
Fred.
# => "DEPRECATION WARNING: bar is deprecated and will be removed from Rails 4.1 (use qux instead)."
Fred.baz
# => "DEPRECATION WARNING: baz is deprecated and will be removed from Rails 4.1 (use Bar#baz instead)."
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'activesupport/lib/active_support/deprecation/method_wrappers.rb', line 28 def deprecate_methods(target_module, *method_names) = method_names. deprecator = .delete(:deprecator) || ActiveSupport::Deprecation.instance method_names += .keys method_names.each do |method_name| target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation| target_module.send(:define_method, "#{target}_with_deprecation#{punctuation}") do |*args, &block| deprecator.deprecation_warning(method_name, [method_name]) send(:"#{target}_without_deprecation#{punctuation}", *args, &block) end end end end |