Class: GQL::Field

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

Defined Under Namespace

Classes: ExecutionContext

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.



36
37
38
39
# File 'lib/gql/field.rb', line 36

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.



34
35
36
# File 'lib/gql/field.rb', line 34

def ast_node
  @ast_node
end

#contextObject (readonly)

Returns the value of attribute context.



34
35
36
# File 'lib/gql/field.rb', line 34

def context
  @context
end

#targetObject (readonly)

Returns the value of attribute target.



34
35
36
# File 'lib/gql/field.rb', line 34

def target
  @target
end

#variablesObject (readonly)

Returns the value of attribute variables.



34
35
36
# File 'lib/gql/field.rb', line 34

def variables
  @variables
end

Class Method Details

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



14
15
16
17
18
19
# File 'lib/gql/field.rb', line 14

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

.execute(parent, ast_node, target, variables, context) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/gql/field.rb', line 21

def execute(parent, ast_node, target, variables, context)
  args    = [target, context, GQL.debug ? parent : nil]
  target  = ExecutionContext.new(*args).instance_exec(&proc)
  field   = new(ast_node, target, variables, context)

  field.value
end

Instance Method Details

#scalar_valueObject



51
52
53
# File 'lib/gql/field.rb', line 51

def scalar_value
  nil
end

#valueObject



41
42
43
44
45
46
47
48
49
# File 'lib/gql/field.rb', line 41

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