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(document) ⇒ Visitor
constructor
A new instance of Visitor.
-
#visit ⇒ void
Visit ‘document` and all children, applying hooks as you go.
Constructor Details
#initialize(document) ⇒ Visitor
Returns a new instance of Visitor.
25 26 27 28 29 30 |
# File 'lib/graphql/language/visitor.rb', line 25 def initialize(document) @document = document @visitors = {} @enter = [] @leave = [] end |
Instance Attribute Details
#enter ⇒ Array<Proc> (readonly)
Returns Hooks to call when entering any node.
21 22 23 |
# File 'lib/graphql/language/visitor.rb', line 21 def enter @enter end |
#leave ⇒ Array<Proc> (readonly)
Returns Hooks to call when leaving any node.
23 24 25 |
# File 'lib/graphql/language/visitor.rb', line 23 def leave @leave end |
Instance Method Details
#[](node_class) ⇒ NodeVisitor
Get a NodeVisitor for ‘node_class`
38 39 40 |
# File 'lib/graphql/language/visitor.rb', line 38 def [](node_class) @visitors[node_class] ||= NodeVisitor.new end |
#visit ⇒ void
This method returns an undefined value.
Visit ‘document` and all children, applying hooks as you go
44 45 46 |
# File 'lib/graphql/language/visitor.rb', line 44 def visit visit_node(@document, nil) end |