Class Roodi::Checks::NpathComplexityCheck
In: lib/roodi/checks/npath_complexity_check.rb
Parent: Roodi::Checks::Check

Methods

Constants

MULTIPLYING_NODE_TYPES = [:if, :while, :until, :for, :case]
ADDING_NODE_TYPES = [:rescue]
COMPLEXITY_NODE_TYPES = MULTIPLYING_NODE_TYPES + ADDING_NODE_TYPES

Public Class methods

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 11
      def initialize(complexity)
        super()
        @complexity = complexity
        @value_stack = []
        @current_value = 1
      end

Public Instance methods

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 34
      def evalute_start_case(node)
        push_value
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 30
      def evalute_start_for(node)
        push_value
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 18
      def evalute_start_if(node)
        push_value
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 38
      def evalute_start_rescue(node)
        push_value
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 26
      def evalute_start_until(node)
        push_value
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 22
      def evalute_start_while(node)
        push_value
      end

Protected Instance methods

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 66
      def leave_adding_conditional
        pop = @value_stack.pop
        puts "#{type}, so adding #{pop}"
        @current_value = @current_value - 1 + pop
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 61
      def leave_multiplying_conditional
        pop = @value_stack.pop
        @current_value = (@current_value + 1) * pop
      end

[Source]

# File lib/roodi/checks/npath_complexity_check.rb, line 56
      def push_value
        @value_stack.push @current_value
        @current_value = 1
      end

[Validate]