Class: LiveCable::Rendering::MethodDependencyVisitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- LiveCable::Rendering::MethodDependencyVisitor
- Defined in:
- lib/live_cable/rendering/method_dependency_visitor.rb
Overview
Visitor that tracks dependencies within a method body
Instance Attribute Summary collapse
- #method_calls ⇒ Set<Symbol> readonly
- #reactive_var_reads ⇒ Set<Symbol> readonly
Instance Method Summary collapse
-
#initialize(component_class, reactive_vars) ⇒ MethodDependencyVisitor
constructor
A new instance of MethodDependencyVisitor.
-
#visit_call_node(node) ⇒ void
Track method calls.
Constructor Details
#initialize(component_class, reactive_vars) ⇒ MethodDependencyVisitor
Returns a new instance of MethodDependencyVisitor.
17 18 19 20 21 22 23 |
# File 'lib/live_cable/rendering/method_dependency_visitor.rb', line 17 def initialize(component_class, reactive_vars) super() @component_class = component_class @method_calls = Set.new @reactive_var_reads = Set.new @reactive_vars = reactive_vars end |
Instance Attribute Details
#method_calls ⇒ Set<Symbol> (readonly)
10 11 12 |
# File 'lib/live_cable/rendering/method_dependency_visitor.rb', line 10 def method_calls @method_calls end |
#reactive_var_reads ⇒ Set<Symbol> (readonly)
13 14 15 |
# File 'lib/live_cable/rendering/method_dependency_visitor.rb', line 13 def reactive_var_reads @reactive_var_reads end |
Instance Method Details
#visit_call_node(node) ⇒ void
This method returns an undefined value.
Track method calls
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/live_cable/rendering/method_dependency_visitor.rb', line 28 def visit_call_node(node) method_name = node.name # Track if this is a reactive variable access @reactive_var_reads << method_name if reactive_vars.include?(method_name) # Track method calls on self (implicit receiver or explicit self) if node.receiver.nil? || node.receiver.is_a?(Prism::SelfNode) @method_calls << method_name end super end |