Class: GraphQL::Language::Visitor
- Inherits:
-
Object
- Object
- GraphQL::Language::Visitor
- Defined in:
- lib/graphql/language/visitor.rb
Overview
Depth-first traversal through the tree, calling hooks at each stop.
Defined Under Namespace
Classes: NodeVisitor
Constant Summary collapse
- SKIP =
If any hook returns this value, the GraphQL::Language::Visitor stops visiting this node right away
:_skip
Instance Attribute Summary collapse
-
#enter ⇒ Array<Proc>
readonly
Hooks to call when entering any node.
-
#leave ⇒ Array<Proc>
readonly
Hooks to call when leaving any node.
Instance Method Summary collapse
-
#[](node_class) ⇒ NodeVisitor
Get a NodeVisitor for ‘node_class`.
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
-
#visit(root, parent = nil) ⇒ void
Visit ‘root` and all children, applying hooks as you go.
Constructor Details
#initialize ⇒ Visitor
Returns a new instance of Visitor.
23 24 25 26 27 |
# File 'lib/graphql/language/visitor.rb', line 23 def initialize @visitors = {} @enter = [] @leave = [] end |
Instance Attribute Details
#enter ⇒ Array<Proc> (readonly)
Returns Hooks to call when entering any node.
19 20 21 |
# File 'lib/graphql/language/visitor.rb', line 19 def enter @enter end |
#leave ⇒ Array<Proc> (readonly)
Returns Hooks to call when leaving any node.
21 22 23 |
# File 'lib/graphql/language/visitor.rb', line 21 def leave @leave end |
Instance Method Details
#[](node_class) ⇒ NodeVisitor
Get a NodeVisitor for ‘node_class`
35 36 37 |
# File 'lib/graphql/language/visitor.rb', line 35 def [](node_class) @visitors[node_class] ||= NodeVisitor.new end |
#visit(root, parent = nil) ⇒ void
This method returns an undefined value.
Visit ‘root` and all children, applying hooks as you go
42 43 44 45 46 |
# File 'lib/graphql/language/visitor.rb', line 42 def visit(root, parent=nil) begin_visit(root, parent) && root.children.reduce(true) { |memo, child| memo && visit(child, root) } end_visit(root, parent) end |