module RuboCop::Cop::StatsD

Constants

METAPROGRAMMING_METHODS
METRIC_METHODS
SINGLETON_CONFIGURATION_METHODS

Private Instance Methods

has_keyword_argument?(node, sym) click to toggle source
# File lib/statsd/instrument/rubocop.rb, line 32
def has_keyword_argument?(node, sym)
  if (kwargs = keyword_arguments(node))
    kwargs.child_nodes.detect do |pair|
      pair.child_nodes[0]&.type == :sym && pair.child_nodes[0].value == sym
    end
  end
end
keyword_arguments(node) click to toggle source
# File lib/statsd/instrument/rubocop.rb, line 40
def keyword_arguments(node)
  return nil if node.arguments.empty?
  last_argument = if node.arguments.last&.type == :block_pass
    node.arguments[node.arguments.length - 2]
  else
    node.arguments[node.arguments.length - 1]
  end

  last_argument&.type == :hash ? last_argument : nil
end
metaprogramming_method?(node) click to toggle source
# File lib/statsd/instrument/rubocop.rb, line 16
def metaprogramming_method?(node)
  METAPROGRAMMING_METHODS.include?(node.method_name)
end
metric_method?(node) click to toggle source
# File lib/statsd/instrument/rubocop.rb, line 20
def metric_method?(node)
  node.receiver&.type == :const &&
    node.receiver&.const_name == "StatsD" &&
    METRIC_METHODS.include?(node.method_name)
end
singleton_configuration_method?(node) click to toggle source
# File lib/statsd/instrument/rubocop.rb, line 26
def singleton_configuration_method?(node)
  node.receiver&.type == :const &&
    node.receiver&.const_name == "StatsD" &&
    SINGLETON_CONFIGURATION_METHODS.include?(node.method_name)
end