Class: GQL::Field

Inherits:
Object
  • Object
show all
Extended by:
Mixins::Common
Includes:
Mixins::HasCalls, Mixins::HasFields
Defined in:
lib/gql/field.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Common

propagate, shutdown

Constructor Details

#initialize(ast_node, target, variables, context) ⇒ Field

Returns a new instance of Field.



26
27
28
29
# File 'lib/gql/field.rb', line 26

def initialize(ast_node, target, variables, context)
  @ast_node, @target = ast_node, target
  @variables, @context = variables, context
end

Instance Attribute Details

#ast_nodeObject (readonly)

Returns the value of attribute ast_node.



24
25
26
# File 'lib/gql/field.rb', line 24

def ast_node
  @ast_node
end

#contextObject (readonly)

Returns the value of attribute context.



24
25
26
# File 'lib/gql/field.rb', line 24

def context
  @context
end

#targetObject (readonly)

Returns the value of attribute target.



24
25
26
# File 'lib/gql/field.rb', line 24

def target
  @target
end

#variablesObject (readonly)

Returns the value of attribute variables.



24
25
26
# File 'lib/gql/field.rb', line 24

def variables
  @variables
end

Class Method Details

.build_class(id, proc, options = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/gql/field.rb', line 12

def build_class(id, proc, options = {})
  Class.new(self).tap do |field_class|
    field_class.id = id.to_s
    field_class.proc = proc
  end
end

Instance Method Details

#scalar_valueObject



41
42
43
# File 'lib/gql/field.rb', line 41

def scalar_value
  nil
end

#valueObject



31
32
33
34
35
36
37
38
39
# File 'lib/gql/field.rb', line 31

def value
  if ast_call = ast_node.call
    value_of_call ast_call
  elsif ast_fields = ast_node.fields
    value_of_fields ast_fields
  else
    scalar_value
  end
end