Skip to content

Commit b8cf128

Browse files
committed
abstract find_matching_nodes
1 parent cd32a52 commit b8cf128

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

lib/synvert/core/rewriter/scope/within_scope.rb

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,31 @@ def process
2222
current_node = @instance.current_node
2323
return unless current_node
2424

25+
matching_nodes = find_matching_nodes(current_node)
2526
@instance.process_with_node current_node do
26-
matching_nodes = []
27-
matching_nodes << current_node if current_node.match? @rules
28-
if @options[:recursive]
29-
current_node.recursive_children do |child_node|
30-
matching_nodes << child_node if child_node.match? @rules
31-
end
32-
else
33-
current_node.children do |child_node|
34-
matching_nodes << child_node if child_node.match? @rules
35-
end
36-
end
3727
matching_nodes.each do |matching_node|
3828
@instance.process_with_node matching_node do
3929
@instance.instance_eval &@block
4030
end
4131
end
4232
end
4333
end
34+
35+
private
36+
37+
def find_matching_nodes(current_node)
38+
matching_nodes = []
39+
if @options[:recursive]
40+
matching_nodes << current_node if current_node.match? @rules
41+
current_node.recursive_children do |child_node|
42+
matching_nodes << child_node if child_node.match? @rules
43+
end
44+
else
45+
current_node.each do |child_node|
46+
matching_nodes << child_node if child_node.match? @rules
47+
end
48+
end
49+
matching_nodes
50+
end
4451
end
4552
end

0 commit comments

Comments
 (0)