Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::ConfigurableNaming

This module provides functionality for checking if names match the configured EnforcedStyle.

Public Instance Methods

after_dot(node, method_name_length, regexp) click to toggle source

Returns a range containing the method name after the given regexp and a dot.

# File lib/rubocop/cop/mixin/configurable_naming.rb, line 33
def after_dot(node, method_name_length, regexp)
  expr = node.loc.expression
  match = /\A#{regexp}\s*\.\s*/.match(expr.source)
  return unless match
  offset = match[0].length
  begin_pos = expr.begin_pos + offset
  Parser::Source::Range.new(expr.source_buffer, begin_pos,
                            begin_pos + method_name_length)
end
check(node, range) click to toggle source
# File lib/rubocop/cop/mixin/configurable_naming.rb, line 12
def check(node, range)
  return unless range

  name = range.source.to_sym
  return if operator?(name)

  if matches_config?(name)
    correct_style_detected
  else
    add_offense(node, range, message(style)) do
      opposite_style_detected
    end
  end
end
matches_config?(name) click to toggle source
# File lib/rubocop/cop/mixin/configurable_naming.rb, line 27
def matches_config?(name)
  name =~ (style == :snake_case ? SNAKE_CASE : CAMEL_CASE)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.