Class: Tailor::Rulers::AllowCamelCaseMethodsRuler

Inherits:
Tailor::Ruler
  • Object
show all
Defined in:
lib/tailor/rulers/allow_camel_case_methods_ruler.rb

Instance Attribute Summary

Attributes inherited from Tailor::Ruler

#lexer_observers

Instance Method Summary collapse

Methods inherited from Tailor::Ruler

#add_child_ruler, #problem_type, #problems

Methods included from Logger::Mixin

included

Constructor Details

#initialize(style, options) ⇒ AllowCamelCaseMethodsRuler

Returns a new instance of AllowCamelCaseMethodsRuler.



6
7
8
9
# File 'lib/tailor/rulers/allow_camel_case_methods_ruler.rb', line 6

def initialize(style, options)
  super(style, options)
  add_lexer_observers :ident
end

Instance Method Details

#ident_update(token, lexed_line, lineno, column) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/tailor/rulers/allow_camel_case_methods_ruler.rb', line 11

def ident_update(token, lexed_line, lineno, column)
  find_event = lexed_line.find { |e| e[1] == :on_kw && e.last == 'def' }

  if find_event && find_event.any?
    measure(token, lineno, column)
  end
end

#measure(token, lineno, column) ⇒ Object

Checks to see if the method name contains capital letters.

Parameters:

  • token (Fixnum)

    The method name.

  • lineno (Fixnum)

    Line the problem was found on.

  • column (Fixnum)

    Column the problem was found on.



24
25
26
27
28
29
30
31
# File 'lib/tailor/rulers/allow_camel_case_methods_ruler.rb', line 24

def measure(token, lineno, column)
  if token.contains_capital_letter?
    problem_message = 'Camel-case method name found.'

    @problems << Problem.new(problem_type, lineno, column,
      problem_message, @options[:level])
  end
end