Class: Ivar::MethodTargetedInstanceVariableReferenceVisitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- Ivar::MethodTargetedInstanceVariableReferenceVisitor
- Defined in:
- lib/ivar/targeted_prism_analysis.rb
Overview
Visitor that collects instance variable references within a specific method definition
Instance Attribute Summary collapse
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Instance Method Summary collapse
-
#initialize(file_path, target_method_name, target_line) ⇒ MethodTargetedInstanceVariableReferenceVisitor
constructor
A new instance of MethodTargetedInstanceVariableReferenceVisitor.
-
#visit_def_node(node) ⇒ Object
Only visit the method definition we’re targeting.
Constructor Details
#initialize(file_path, target_method_name, target_line) ⇒ MethodTargetedInstanceVariableReferenceVisitor
Returns a new instance of MethodTargetedInstanceVariableReferenceVisitor.
72 73 74 75 76 77 78 79 |
# File 'lib/ivar/targeted_prism_analysis.rb', line 72 def initialize(file_path, target_method_name, target_line) super() @file_path = file_path @target_method_name = target_method_name @target_line = target_line @references = [] @in_target_method = false end |
Instance Attribute Details
#references ⇒ Object (readonly)
Returns the value of attribute references.
70 71 72 |
# File 'lib/ivar/targeted_prism_analysis.rb', line 70 def references @references end |
Instance Method Details
#visit_def_node(node) ⇒ Object
Only visit the method definition we’re targeting
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ivar/targeted_prism_analysis.rb', line 82 def visit_def_node(node) # Check if this is our target method if node.name.to_sym == @target_method_name && node.location.start_line == @target_line # Found our target method, now collect all instance variable references within it collector = IvarCollector.new(@file_path, @target_method_name) node.body&.accept(collector) @references = collector.references false else # Sometimes methods are found inside other methods... node.body&.accept(self) true end end |