module Dry::Core::Deprecations::Interface
Public Instance Methods
deprecate(old_name, new_name = nil, message: nil)
click to toggle source
Mark instance method as deprecated
@param [Symbol] old_name deprecated method @param [Symbol] new_name replacement (not required) @option [String] message optional deprecation message
# File lib/dry/core/deprecations.rb, line 157 def deprecate(old_name, new_name = nil, message: nil) full_msg = Deprecations.deprecated_name_message( "#{name}##{old_name}", new_name ? "#{name}##{new_name}" : nil, message ) mod = self if new_name undef_method old_name if method_defined?(old_name) define_method(old_name) do |*args, &block| mod.warn("#{full_msg}\n#{STACK.()}") __send__(new_name, *args, &block) end else aliased_name = :"#{old_name}_without_deprecation" alias_method aliased_name, old_name private aliased_name undef_method old_name define_method(old_name) do |*args, &block| mod.warn("#{full_msg}\n#{STACK.()}") __send__(aliased_name, *args, &block) end end end
deprecate_class_method(old_name, new_name = nil, message: nil)
click to toggle source
Mark class-level method as deprecated
@param [Symbol] old_name deprecated method @param [Symbol] new_name replacement (not required) @option [String] message optional deprecation message
# File lib/dry/core/deprecations.rb, line 190 def deprecate_class_method(old_name, new_name = nil, message: nil) full_msg = Deprecations.deprecated_name_message( "#{name}.#{old_name}", new_name ? "#{name}.#{new_name}" : nil, message ) meth = new_name ? method(new_name) : method(old_name) singleton_class.instance_exec do undef_method old_name if method_defined?(old_name) define_method(old_name) do |*args, &block| warn("#{full_msg}\n#{STACK.()}") meth.call(*args, &block) end end end
deprecate_constant(constant_name, message: nil)
click to toggle source
Mark a constant as deprecated @param [Symbol] constant_name constant name to be deprecated @option [String] message optional deprecation message
Calls superclass method
# File lib/dry/core/deprecations.rb, line 212 def deprecate_constant(constant_name, message: nil) value = const_get(constant_name) remove_const(constant_name) full_msg = Deprecations.deprecated_name_message( "#{name}::#{constant_name}", message ) mod = Module.new do define_method(:const_missing) do |missing| if missing == constant_name warn("#{full_msg}\n#{STACK.()}") value else super(missing) end end end extend(mod) end
deprecation_tag(tag = nil)
click to toggle source
Sets/gets deprecation tag
@option [String,Symbol] tag tag
# File lib/dry/core/deprecations.rb, line 137 def deprecation_tag(tag = nil) if defined?(@deprecation_tag) @deprecation_tag else @deprecation_tag = tag end end
warn(msg)
click to toggle source
Issue a tagged warning message
@param [String] msg warning message
# File lib/dry/core/deprecations.rb, line 148 def warn(msg) Deprecations.warn(msg, tag: deprecation_tag) end