Module: SimpleCov::StaticCoverageExtractor::MethodCollector
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Included In:
| |
| Defined in: | lib/simplecov/static_coverage_extractor/method_collector.rb |
Overview
Instance Method Summary
-
#visit_class_node(node)
Track class/module nesting so method tuples carry the lexical class name.
-
#visit_def_node(node)
def name(...)anddef self.name(...)both produce DefNode. - #visit_module_node(node)
-
#constant_name(node)
private
Render a constant path (e.g.,
Foo::Bar) as its source-form string. -
#with_class(name)
private
simplecov:enable.
Instance Method Details
#constant_name(node) (private)
Render a constant path (e.g., Foo::Bar) as its source-form
string. Defensive nil / to_s fallbacks: ClassNode and ModuleNode
always carry a constant_path in practice.
simplecov:disable
# File 'lib/simplecov/static_coverage_extractor/method_collector.rb', line 39
def constant_name(node) return "<anonymous>" if node.nil? return node.slice if node.respond_to?(:slice) node.to_s end
#visit_class_node(node)
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.
# 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)
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).
# 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)
[ GitHub ]# 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
#with_class(name) (private)
simplecov:enable
# File 'lib/simplecov/static_coverage_extractor/method_collector.rb', line 47
def with_class(name) @class_stack.push(name) yield ensure @class_stack.pop end