Class: GraphQL::Language::Nodes::AbstractNode
- Inherits:
-
Object
- Object
- GraphQL::Language::Nodes::AbstractNode
- Defined in:
- lib/graphql/language/nodes.rb
Overview
AbstractNode creates classes who:
-
require their keyword arguments, throw ArgumentError if they don’t match
-
expose accessors for keyword arguments
Direct Known Subclasses
Argument, Directive, Document, EnumTypeDefinition, Field, FieldDefinition, FragmentDefinition, FragmentSpread, InlineFragment, InputObject, InputObjectTypeDefinition, InputValueDefinition, InterfaceTypeDefinition, NameOnlyNode, ObjectTypeDefinition, OperationDefinition, SchemaDefinition, UnionTypeDefinition, VariableDefinition, WrapperType
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#line ⇒ Object
Returns the value of attribute line.
Class Method Summary collapse
- .child_attributes(*attr_names) ⇒ Object
- .inherited(subclass) ⇒ Object
- .scalar_attributes(*attr_names) ⇒ Object
Instance Method Summary collapse
-
#children ⇒ GraphQL::Language::Nodes::AbstractNode
All nodes in the tree below this one.
- #eql?(other) ⇒ Boolean
-
#initialize(options = {}) ⇒ AbstractNode
constructor
A new instance of AbstractNode.
-
#initialize_node(options = {}) ⇒ Object
This is called with node-specific options.
- #position ⇒ Object
- #scalars ⇒ Object
- #to_query_string ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AbstractNode
Returns a new instance of AbstractNode.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/graphql/language/nodes.rb', line 11 def initialize(={}) if .key?(:position_source) position_source = .delete(:position_source) @line, @col = position_source.line_and_column elsif .key?(:line) @line = .delete(:line) @col = .delete(:col) end initialize_node() end |
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col.
8 9 10 |
# File 'lib/graphql/language/nodes.rb', line 8 def col @col end |
#line ⇒ Object
Returns the value of attribute line.
8 9 10 |
# File 'lib/graphql/language/nodes.rb', line 8 def line @line end |
Class Method Details
.child_attributes(*attr_names) ⇒ Object
58 59 60 61 |
# File 'lib/graphql/language/nodes.rb', line 58 def child_attributes(*attr_names) @child_attributes ||= [] @child_attributes += attr_names end |
.inherited(subclass) ⇒ Object
48 49 50 51 |
# File 'lib/graphql/language/nodes.rb', line 48 def inherited(subclass) subclass.scalar_attributes(*@scalar_attributes) subclass.child_attributes(*@child_attributes) end |
.scalar_attributes(*attr_names) ⇒ Object
53 54 55 56 |
# File 'lib/graphql/language/nodes.rb', line 53 def scalar_attributes(*attr_names) @scalar_attributes ||= [] @scalar_attributes += attr_names end |
Instance Method Details
#children ⇒ GraphQL::Language::Nodes::AbstractNode
Returns all nodes in the tree below this one.
36 37 38 39 40 |
# File 'lib/graphql/language/nodes.rb', line 36 def children self.class.child_attributes .map { |attr_name| public_send(attr_name) } .flatten end |
#eql?(other) ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/graphql/language/nodes.rb', line 28 def eql?(other) return true if equal?(other) other.is_a?(self.class) && other.scalars.eql?(self.scalars) && other.children.eql?(self.children) end |
#initialize_node(options = {}) ⇒ Object
This is called with node-specific options
24 25 26 |
# File 'lib/graphql/language/nodes.rb', line 24 def initialize_node(={}) raise NotImplementedError end |
#position ⇒ Object
64 65 66 |
# File 'lib/graphql/language/nodes.rb', line 64 def position [line, col] end |
#scalars ⇒ Object
42 43 44 45 |
# File 'lib/graphql/language/nodes.rb', line 42 def scalars self.class.scalar_attributes .map { |attr_name| public_send(attr_name) } end |
#to_query_string ⇒ Object
68 69 70 |
# File 'lib/graphql/language/nodes.rb', line 68 def to_query_string Generation.generate(self) end |