Class: LegacyComplexityHandler

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

Constant Summary collapse

BRANCH_TYPES =
[TkRESCUE, TkENSURE, TkIF, TkIF_MOD, TkELSIF, TkELSE, TkUNLESS,
TkWHEN, TkWHILE, TkWHILE_MOD, TkUNTIL, TkUNTIL_MOD, TkFOR, TkQUESTION, TkCOLON,
TkLBRACE, TkDO]

Instance Method Summary collapse

Instance Method Details

#processObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/complexity.rb', line 29

def process
  nobj, mscope = namespace, scope
  if statement.tokens.to_s =~ /^def\s+(#{METHODMATCH})/m
    meth = $1.gsub(/\s+/,'')
    if meth =~ /(?:#{NSEPQ}|#{CSEPQ})([^#{NSEP}#{CSEPQ}]+)$/
      mscope, meth = :class, $1
      nobj = P(namespace, $`) unless $` == "self"
    end
    
    obj = MethodObject.new(nobj, meth, mscope)
    obj[:complexity] = 1
    statement.block.each do |token|
      obj[:complexity] += 1 if BRANCH_TYPES.include?(token.class)
    end
  end
end