Class: Synvert::Core::Rewriter::QueryScope
- Defined in:
- lib/synvert/core/rewriter/scope/query_scope.rb
Overview
QueryScope finds out nodes by using node query language, then changes its scope to matching node.
Instance Method Summary collapse
-
#initialize(instance, nql, options = {}) { ... } ⇒ QueryScope
constructor
Initialize a QueryScope.
-
#process ⇒ Object
Find out the matching nodes.
Constructor Details
#initialize(instance, nql, options = {}) { ... } ⇒ QueryScope
Initialize a QueryScope.
12 13 14 15 16 17 |
# File 'lib/synvert/core/rewriter/scope/query_scope.rb', line 12 def initialize(instance, nql, = {}, &block) super(instance, &block) @options = { including_self: true, stop_at_first_match: false, recursive: true }.merge() @node_query = NodeQuery.new(nql) 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/synvert/core/rewriter/scope/query_scope.rb', line 24 def process current_node = @instance.current_node return unless current_node matching_nodes = @node_query.query_nodes(current_node, @options) @instance.process_with_node(current_node) do matching_nodes.each do |node| @instance.process_with_node(node) do @instance.instance_eval(&@block) end end end end |