Class: GQLi::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/gqli/node.rb

Overview

Node wrapper

Instance Attribute Summary collapse

Attributes inherited from Base

#__depth, #__name, #__nodes

Instance Method Summary collapse

Methods inherited from Base

#___, #__enum, #__node, #__on

Constructor Details

#initialize(name, params = {}, depth = 1, &block) ⇒ Node

Returns a new instance of Node.



10
11
12
13
# File 'lib/gqli/node.rb', line 10

def initialize(name, params = {}, depth = 1, &block)
  super(name, depth, &block)
  @__params = params
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GQLi::Base

Instance Attribute Details

#__paramsObject (readonly)

Returns the value of attribute __params.



8
9
10
# File 'lib/gqli/node.rb', line 8

def __params
  @__params
end

Instance Method Details

#to_gqlObject

Serializes to a GraphQL string



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gqli/node.rb', line 16

def to_gql
  result = '  ' * __depth + __name
  result += __params_to_s(__params, true) unless __params.empty?
  unless __nodes.empty?
    result += " {\n"
    result += __nodes.map(&:to_gql).join("\n")
    result += "\n#{'  ' * __depth}}"
  end

  result
end