Module: Uncruft::Deprecatable::ClassMethods

Defined in:
lib/uncruft/deprecatable.rb

Instance Method Summary collapse

Instance Method Details

#deprecate_attribute(attribute, message:) ⇒ Object



6
7
8
9
# File 'lib/uncruft/deprecatable.rb', line 6

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

#deprecate_method(method, message:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/uncruft/deprecatable.rb', line 11

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

  prepended_method.module_eval do
    define_method method do |*args, &block|
      ActiveSupport::Deprecation.warn(message)
      super(*args, &block)
    end
  end

  prepend prepended_method
end