Class: SimpleCov::StaticCoverageExtractor::Visitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- SimpleCov::StaticCoverageExtractor::Visitor
- Includes:
- MethodCollector
- Defined in:
- lib/simplecov/static_coverage_extractor/visitor.rb
Overview
Prism visitor that accumulates branch and method tuples in the
shape Ruby's Coverage reports. Tuple ids are sequential across
the file — Coverage uses sequential ids too, so this matches the
conventional shape. Only defined when Prism is loadable;
StaticCoverageExtractor.available? is the runtime gate.
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
Instance Method Summary collapse
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
- #visit_call_node(node) ⇒ Object
- #visit_case_match_node(node) ⇒ Object
-
#visit_case_node(node) ⇒ Object
case/whenandcase/in(pattern matching) parse as CaseNode and CaseMatchNode respectively. -
#visit_if_node(node) ⇒ Object
if/unless/ postfix-if / postfix-unless / ternary all parse as IfNode (or UnlessNode). - #visit_unless_node(node) ⇒ Object
- #visit_until_node(node) ⇒ Object
-
#visit_while_node(node) ⇒ Object
while/untilloops get a single:bodyarm.
Methods included from MethodCollector
#visit_class_node, #visit_def_node, #visit_module_node
Constructor Details
#initialize ⇒ Visitor
Returns a new instance of Visitor.
35 36 37 38 39 40 41 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 35 def initialize super @branches = {} @methods = {} @next_id = 0 @class_stack = [] end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
33 34 35 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 33 def branches @branches end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
33 34 35 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 33 def methods @methods end |
Instance Method Details
#visit_call_node(node) ⇒ Object
59 60 61 62 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 59 def visit_call_node(node) (node) if node.respond_to?(:safe_navigation?) && node. super end |
#visit_case_match_node(node) ⇒ Object
72 73 74 75 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 72 def visit_case_match_node(node) emit_case_like(node, :in) super end |
#visit_case_node(node) ⇒ Object
case/when and case/in (pattern matching) parse as CaseNode
and CaseMatchNode respectively. When there's no explicit else,
Coverage synthesizes one at the case's range.
67 68 69 70 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 67 def visit_case_node(node) emit_case_like(node, :when) super end |
#visit_if_node(node) ⇒ Object
if / unless / postfix-if / postfix-unless / ternary all parse
as IfNode (or UnlessNode). Both carry a then arm (the
statements body) and an optional subsequent (an ElseNode for
else, another IfNode for elsif). When the subsequent is
missing, Coverage synthesizes a :else arm attributed to the
whole condition's range — we do the same.
49 50 51 52 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 49 def visit_if_node(node) emit_if_like(node, :if) super end |
#visit_unless_node(node) ⇒ Object
54 55 56 57 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 54 def visit_unless_node(node) emit_if_like(node, :unless) super end |
#visit_until_node(node) ⇒ Object
84 85 86 87 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 84 def visit_until_node(node) emit_loop(node, :until) super end |
#visit_while_node(node) ⇒ Object
while / until loops get a single :body arm. No synthetic
else (the loop either runs the body or doesn't).
79 80 81 82 |
# File 'lib/simplecov/static_coverage_extractor/visitor.rb', line 79 def visit_while_node(node) emit_loop(node, :while) super end |