Class: Synvert::Core::Rewriter::WithinScope
- Defined in:
- lib/synvert/core/rewriter/scope/within_scope.rb
Overview
WithinScope finds out nodes which match rules, then changes its scope to matching node.
Instance Method Summary collapse
-
#initialize(instance, rules, options = {}) { ... } ⇒ WithinScope
constructor
Initialize a WithinScope.
-
#process ⇒ Object
Find out the matching nodes.
Constructor Details
#initialize(instance, rules, options = {}) { ... } ⇒ WithinScope
Initialize a WithinScope.
12 13 14 15 16 |
# File 'lib/synvert/core/rewriter/scope/within_scope.rb', line 12 def initialize(instance, rules, = {}, &block) super(instance, &block) @rules = rules @options = end |
Instance Method Details
#process ⇒ Object
Find out the matching nodes. It checks the current node and iterates all child nodes, then run the block code on each matching node.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/synvert/core/rewriter/scope/within_scope.rb', line 21 def process current_node = @instance.current_node return unless current_node matching_nodes = if @options[:direct] find_direct_matching_nodes(current_node) elsif @options[:stop_when_match] find_matching_nodes(current_node) else find_recursive_matching_nodes(current_node) end @instance.process_with_node current_node do matching_nodes.each do |matching_node| @instance.process_with_node matching_node do @instance.instance_eval(&@block) end end end end |