class RuboCop::Cop::Lint::DeprecatedClassMethods

This cop checks for uses of the deprecated class method usages.

Constants

DEPRECATED_METHODS_OBJECT
MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 45
def autocorrect(node)
  lambda do |corrector|
    check(node) do |data|
      corrector.replace(node.loc.selector,
                        data.replacement_method.to_s)
    end
  end
end
on_send(node) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 36
def on_send(node)
  check(node) do |data|
    add_offense(node, :selector,
                format(MSG,
                       deprecated_method(data),
                       replacement_method(data)))
  end
end

Private Instance Methods

check(node) { |data| ... } click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 56
def check(node)
  receiver, method_name, *_args = *node

  DEPRECATED_METHODS_OBJECT.each do |data|
    next unless data.class_nodes.include?(receiver)
    next unless method_name == data.deprecated_method
    yield data
  end
end
deprecated_method(data) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 66
def deprecated_method(data)
  method_call(data.class_constant, data.deprecated_method)
end
method_call(class_constant, method) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 74
def method_call(class_constant, method)
  format('%s.%s', class_constant, method)
end
replacement_method(data) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 70
def replacement_method(data)
  method_call(data.class_constant, data.replacement_method)
end