Module: Uncruft::Deprecatable::ClassMethods

Defined in:
lib/uncruft/deprecatable.rb

Instance Method Summary collapse

Instance Method Details

#deprecate_attribute(attribute, message:) ⇒ Object



8
9
10
11
# File 'lib/uncruft/deprecatable.rb', line 8

def deprecate_attribute(attribute, message:)
  deprecate_method(attribute, message:)
  deprecate_method :"#{attribute}=", message:
end

#deprecate_method(method, message:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/uncruft/deprecatable.rb', line 13

def deprecate_method(method, message:)
  prepended_method = Module.new

  prepended_method.module_eval do
    define_method method do |*args, **kwargs, &block|
      Uncruft.deprecator.warn(
        message,
        caller_locations(1).reject { |loc| loc.path.start_with?(Uncruft::GEM_ROOT) },
      )
      super(*args, **kwargs, &block)
    end
  end

  prepend prepended_method
end