Class: Roodi::Checks::NpathComplexityMethodCheck

Inherits:
NpathComplexityCheck show all
Defined in:
lib/roodi/checks/npath_complexity_method_check.rb

Overview

Checks NPATH complexity of a method against a specified limit.

Constant Summary collapse

DEFAULT_COMPLEXITY =
8

Constants inherited from NpathComplexityCheck

Roodi::Checks::NpathComplexityCheck::ADDING_NODE_TYPES, Roodi::Checks::NpathComplexityCheck::COMPLEXITY_NODE_TYPES, Roodi::Checks::NpathComplexityCheck::MULTIPLYING_NODE_TYPES

Constants inherited from Check

Check::NODE_TYPES

Instance Attribute Summary

Attributes inherited from NpathComplexityCheck

#complexity

Instance Method Summary collapse

Methods inherited from NpathComplexityCheck

#evalute_start_case, #evalute_start_for, #evalute_start_if, #evalute_start_rescue, #evalute_start_until, #evalute_start_while

Methods inherited from Check

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

Constructor Details

#initializeNpathComplexityMethodCheck

Returns a new instance of NpathComplexityMethodCheck.



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

def initialize
  super(DEFAULT_COMPLEXITY)
end

Instance Method Details

#evaluate_end_defn(node) ⇒ Object



23
24
25
# File 'lib/roodi/checks/npath_complexity_method_check.rb', line 23

def evaluate_end_defn(node)
  add_error "Method name \"#{@method_name}\" n-path complexity is #{@current_value}.  It should be #{@complexity} or less." unless @current_value <= @complexity
end

#evaluate_start_defn(node) ⇒ Object



18
19
20
21
# File 'lib/roodi/checks/npath_complexity_method_check.rb', line 18

def evaluate_start_defn(node)
  @method_name = @node[1]
  push_value
end

#interesting_nodesObject



14
15
16
# File 'lib/roodi/checks/npath_complexity_method_check.rb', line 14

def interesting_nodes
  [:defn] + COMPLEXITY_NODE_TYPES
end