Class: LiveCable::Rendering::DependencyVisitor
- Inherits:
-
Prism::Visitor
- Object
- Prism::Visitor
- LiveCable::Rendering::DependencyVisitor
- Defined in:
- lib/live_cable/rendering/dependency_visitor.rb
Instance Attribute Summary collapse
- #component_method_calls ⇒ Set<Symbol> readonly
- #local_reads ⇒ Array<Symbol> readonly
- #local_writes ⇒ Array<Symbol> readonly
Instance Method Summary collapse
-
#initialize ⇒ DependencyVisitor
constructor
A new instance of DependencyVisitor.
-
#visit_call_node(node) ⇒ void
Track variable method calls (e.g.,
foowithout parens) Also track component.method_name calls. -
#visit_local_variable_and_write_node(node) ⇒ void
Track local variable and writes (&&=).
-
#visit_local_variable_operator_write_node(node) ⇒ void
Track local variable operator writes (+=, ||=, etc).
-
#visit_local_variable_or_write_node(node) ⇒ void
Track local variable or writes (||=).
-
#visit_local_variable_read_node(node) ⇒ void
Track all local variable reads.
-
#visit_local_variable_write_node(node) ⇒ void
Track local variable writes.
Constructor Details
#initialize ⇒ DependencyVisitor
Returns a new instance of DependencyVisitor.
15 16 17 18 19 20 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 15 def initialize super @local_reads = [] @local_writes = [] @component_method_calls = Set.new end |
Instance Attribute Details
#component_method_calls ⇒ Set<Symbol> (readonly)
13 14 15 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 13 def component_method_calls @component_method_calls end |
#local_reads ⇒ Array<Symbol> (readonly)
7 8 9 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 7 def local_reads @local_reads end |
#local_writes ⇒ Array<Symbol> (readonly)
10 11 12 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 10 def local_writes @local_writes end |
Instance Method Details
#visit_call_node(node) ⇒ void
This method returns an undefined value.
Track variable method calls (e.g., foo without parens)
Also track component.method_name calls
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 34 def visit_call_node(node) # Track variable calls (implicit self) @local_reads |= [node.name] if node.variable_call? # Track component.method_name calls if component_receiver?(node.receiver) @component_method_calls << node.name end super end |
#visit_local_variable_and_write_node(node) ⇒ void
This method returns an undefined value.
Track local variable and writes (&&=)
66 67 68 69 70 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 66 def visit_local_variable_and_write_node(node) @local_writes |= [node.name] @local_reads |= [node.name] super end |
#visit_local_variable_operator_write_node(node) ⇒ void
This method returns an undefined value.
Track local variable operator writes (+=, ||=, etc)
57 58 59 60 61 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 57 def visit_local_variable_operator_write_node(node) @local_writes |= [node.name] @local_reads |= [node.name] # Reads before writing super end |
#visit_local_variable_or_write_node(node) ⇒ void
This method returns an undefined value.
Track local variable or writes (||=)
75 76 77 78 79 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 75 def visit_local_variable_or_write_node(node) @local_writes |= [node.name] @local_reads |= [node.name] super end |
#visit_local_variable_read_node(node) ⇒ void
This method returns an undefined value.
Track all local variable reads
25 26 27 28 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 25 def visit_local_variable_read_node(node) @local_reads |= [node.name] super end |
#visit_local_variable_write_node(node) ⇒ void
This method returns an undefined value.
Track local variable writes
49 50 51 52 |
# File 'lib/live_cable/rendering/dependency_visitor.rb', line 49 def visit_local_variable_write_node(node) @local_writes |= [node.name] super end |