Class: GQL::Array

Inherits:
Field
  • Object
show all
Defined in:
lib/gql/array.rb

Instance Attribute Summary

Attributes inherited from Field

#ast_node, #context, #target, #variables

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Field

execute, #initialize, #scalar_value

Methods included from Mixins::Common

#propagate, #shutdown

Constructor Details

This class inherits a constructor from GQL::Field

Class Method Details

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gql/array.rb', line 8

def build_class(id, proc, options = {})
  item_class = options.delete(:item_class) || self.item_class
  item_class = Object.build_class(:item, -> { target }, object_class: item_class)

  Class.new(self).tap do |field_class|
    field_class.id = id
    field_class.proc = proc
    field_class.item_class = item_class

    if item_class && item_class.name.nil?
      field_class.const_set :Item, item_class
    end
  end
end

Instance Method Details

#valueObject



24
25
26
27
28
29
# File 'lib/gql/array.rb', line 24

def value
  target.map do |item|
    field = self.class.item_class.new(ast_node, item, variables, context)
    field.value
  end
end