Class: ComplexityHandler

Inherits:
YARD::Handlers::Ruby::Base
  • Object
show all
Defined in:
lib/complexity.rb

Constant Summary collapse

BRANCH_TYPES =
[:if, :if_mod, :unless, :unless_mod, :when, :elsif, :else,
:while, :while_mod, :until, :until_mod, :for, :do_block, :brace_block, :rescue]

Instance Method Summary collapse

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/complexity.rb', line 10

def process
  return unless YARD::CodeObjects::MethodObject === owner
  return unless [:def, :defs].include? statement.parent.parent.type
  
  owner[:complexity] = 1
  statement.parent.last.traverse do |node|
    owner[:complexity] += 1 if BRANCH_TYPES.include?(node.type)
    owner[:complexity] += 2 if node.type == :ifop
  end
end