module ActiveSupport::Deprecation::MethodWrapper
def deprecate_methods(target_module, *method_names)
DEPRECATION WARNING: eee is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):18)
Fred.new.eee
# => [:eee]
custom_deprecator.deprecate_methods(Fred, eee: :zzz)
custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
Using a custom deprecator directly:
# => nil
DEPRECATION WARNING: ddd is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):15)
Fred.new.ddd
# => [:ddd]
ActiveSupport::Deprecation.deprecate_methods(Fred, ddd: :zzz, deprecator: custom_deprecator)
custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
Passing in a custom deprecator:
# => nil
# DEPRECATION WARNING: ccc is deprecated and will be removed from Rails 5.1 (use Bar#ccc instead). (called from irb_binding at (irb):12)
Fred.new.ccc
# => nil
# DEPRECATION WARNING: bbb is deprecated and will be removed from Rails 5.1 (use zzz instead). (called from irb_binding at (irb):11)
Fred.new.bbb
# => nil
# DEPRECATION WARNING: aaa is deprecated and will be removed from Rails 5.1. (called from irb_binding at (irb):10)
Fred.new.aaa
# => Fred
ActiveSupport::Deprecation.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
Using the default deprecator:
end
def eee; end
def ddd; end
def ccc; end
def bbb; end
def aaa; end
class Fred
Declare that a method has been deprecated.
def deprecate_methods(target_module, *method_names) options = method_names.extract_options! deprecator = options.delete(:deprecator) || self method_names += options.keys mod = nil method_names.each do |method_name| message = options[method_name] if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name) method = target_module.instance_method(method_name) target_module.module_eval do redefine_method(method_name) do |*args, &block| deprecator.deprecation_warning(method_name, message) method.bind_call(self, *args, &block) end ruby2_keywords(method_name) end else mod ||= Module.new mod.module_eval do define_method(method_name) do |*args, &block| deprecator.deprecation_warning(method_name, message) super(*args, &block) end ruby2_keywords(method_name) end end end target_module.prepend(mod) if mod end