Class: Roodi::Checks::NameCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/roodi/checks/name_check.rb

Overview

Checking that a node’s name matches a pattern

Direct Known Subclasses

ClassNameCheck, MethodNameCheck, ModuleNameCheck

Constant Summary

Constants inherited from Check

Check::NODE_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Check

#add_error, #end_file, #errors, #evaluate_end, #evaluate_node, #evaluate_node_end, #evaluate_node_start, #initialize, make, #position, #start_file

Constructor Details

This class inherits a constructor from Roodi::Checks::Check

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



8
9
10
# File 'lib/roodi/checks/name_check.rb', line 8

def pattern
  @pattern
end

Instance Method Details

#evaluate_start(node) ⇒ Object



10
11
12
13
# File 'lib/roodi/checks/name_check.rb', line 10

def evaluate_start(node)
  name = find_name(node)
  add_error "#{message_prefix} name \"#{name}\" should match pattern #{@pattern.inspect}" unless name.to_s =~ @pattern
end

#find_name(node) ⇒ Object



15
16
17
# File 'lib/roodi/checks/name_check.rb', line 15

def find_name(node)
  node[1].class == Symbol ? node[1] : node[1].last
end