class RuboCop::Cop::Lint::DeprecatedClassMethods

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

@example

# bad

File.exists?(some_path)

@example

# good

File.exist?(some_path)

Constants

DEPRECATED_METHODS_OBJECT
MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 56
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 47
def on_send(node)
  check(node) do |data|
    message = format(MSG, deprecated_method(data),
                     replacement_method(data))

    add_offense(node, location: :selector, message: message)
  end
end

Private Instance Methods

check(node) { |data| ... } click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 67
def check(node)
  DEPRECATED_METHODS_OBJECT.each do |data|
    next unless data.class_nodes.include?(node.receiver)
    next unless node.method?(data.deprecated_method)
    yield data
  end
end
deprecated_method(data) click to toggle source
# File lib/rubocop/cop/lint/deprecated_class_methods.rb, line 75
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 83
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 79
def replacement_method(data)
  method_call(data.class_constant, data.replacement_method)
end