Class: Transpec::AST::Scanner
- Inherits:
-
Object
- Object
- Transpec::AST::Scanner
- Defined in:
- lib/transpec/ast/scanner.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(&block) ⇒ Scanner
constructor
A new instance of Scanner.
- #scan(origin_node, yield_origin_node = false) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Scanner
Returns a new instance of Scanner.
14 15 16 17 |
# File 'lib/transpec/ast/scanner.rb', line 14 def initialize(&block) @callback = block @ancestor_nodes = [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/transpec/ast/scanner.rb', line 6 def context @context end |
Class Method Details
.scan(origin_node, &block) ⇒ Object
8 9 10 11 12 |
# File 'lib/transpec/ast/scanner.rb', line 8 def self.scan(origin_node, &block) instance = new(&block) instance.scan(origin_node, true) nil end |
Instance Method Details
#scan(origin_node, yield_origin_node = false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/transpec/ast/scanner.rb', line 19 def scan(origin_node, yield_origin_node = false) return unless origin_node yield_node(origin_node) if yield_origin_node @ancestor_nodes.push(origin_node) origin_node.each_child_node do |child_node| yield_node(child_node) scan(child_node) end @ancestor_nodes.pop end |