Class: Simplabs::Excellent::Parsing::MethodContext

Inherits:
SexpContext
  • Object
show all
Includes:
AbcMeasure, CyclomaticComplexityMeasure, FlogMeasure
Defined in:
lib/simplabs/excellent/parsing/method_context.rb

Overview

:nodoc:

Direct Known Subclasses

SingletonMethodContext

Constant Summary

Constants included from FlogMeasure

FlogMeasure::BRANCHES, FlogMeasure::SCORES

Constants included from AbcMeasure

AbcMeasure::CONDITIONS

Constants included from CyclomaticComplexityMeasure

CyclomaticComplexityMeasure::COMPLEXITY_NODE_TYPES

Instance Attribute Summary collapse

Attributes inherited from SexpContext

#file, #line, #name, #parent

Instance Method Summary collapse

Methods included from FlogMeasure

#flog_score, #process_alias, #process_and, #process_attrasgn, #process_attrset, #process_block_pass, #process_call, #process_case, #process_dasgn_curr, #process_else, #process_iasgn, #process_if, #process_iter, #process_lasgn, #process_lit, #process_masgn, #process_or, #process_rescue, #process_sclass, #process_super, #process_until, #process_when, #process_while, #process_yield

Methods included from AbcMeasure

#abc_score, #process_call, #process_lasgn, #process_vcall

Methods included from CyclomaticComplexityMeasure

#cc_score, #process_and, #process_case, #process_for, #process_if, #process_or, #process_rescue, #process_until, #process_when, #process_while

Methods inherited from SexpContext

#method_missing

Constructor Details

#initialize(exp, parent) ⇒ MethodContext

Returns a new instance of MethodContext.



21
22
23
24
25
26
27
28
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 21

def initialize(exp, parent)
  super
  @parameters = []
  @name       = exp[1].to_s
  @parent.methods << self if @parent && (@parent.is_a?(ClassContext) || @parent.is_a?(ModuleContext))
  @calls      = Hash.new(0)
  @line_count = count_lines
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Simplabs::Excellent::Parsing::SexpContext

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



18
19
20
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 18

def calls
  @calls
end

#line_countObject (readonly)

Returns the value of attribute line_count.



19
20
21
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 19

def line_count
  @line_count
end

#parametersObject (readonly)

Returns the value of attribute parameters.



17
18
19
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 17

def parameters
  @parameters
end

Instance Method Details

#full_nameObject



34
35
36
37
38
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 34

def full_name
  parent = @parent.is_a?(BlockContext) ? @parent.parent : @parent
  return @name if parent.blank?
  "#{parent.full_name}##{@name}"
end

#has_parameter?(parameter) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 30

def has_parameter?(parameter)
  @parameters.include?(parameter)
end

#record_call_to(context) ⇒ Object



40
41
42
# File 'lib/simplabs/excellent/parsing/method_context.rb', line 40

def record_call_to(context)
  @calls[context] += 1
end