Module: SimpleCov::StaticCoverageExtractor::MethodCollector

Included in:
Visitor
Defined in:
lib/simplecov/static_coverage_extractor/method_collector.rb

Overview

Visitor mixin that collects method tuples and tracks the lexical class / module nesting that names them, in the shape Ruby’s ‘Coverage` reports methods. Mixed into `Visitor`, it shares that visitor’s ‘@methods` / `@class_stack` state and keeps the method-collection concern separate from branch extraction.

Instance Method Summary collapse

Instance Method Details

#visit_class_node(node) ⇒ Object

Track class/module nesting so method tuples carry the lexical class name. Module + Class are both treated as namespaces here since ‘Coverage` reports both as the constant.



14
15
16
# File 'lib/simplecov/static_coverage_extractor/method_collector.rb', line 14

def visit_class_node(node)
  with_class(constant_name(node.constant_path)) { super }
end

#visit_def_node(node) ⇒ Object

‘def name(…)` and `def self.name(…)` both produce DefNode. The class context is the surrounding lexical class/module (or `Object` at the top level, matching `Coverage`’s convention).



25
26
27
28
29
30
31
# File 'lib/simplecov/static_coverage_extractor/method_collector.rb', line 25

def visit_def_node(node)
  loc = node.location
  class_name = @class_stack.last || "Object"
  key = [class_name, node.name, loc.start_line, loc.start_column, loc.end_line, loc.end_column]
  @methods[key] = 0
  super
end

#visit_module_node(node) ⇒ Object



18
19
20
# File 'lib/simplecov/static_coverage_extractor/method_collector.rb', line 18

def visit_module_node(node)
  with_class(constant_name(node.constant_path)) { super }
end