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

#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
# File 'lib/gql/array.rb', line 8

def build_class(id, proc, options = {})
  item_class = options.delete(:item_class) || self.item_class
  item_class = ::Hash.new(item_class) unless item_class.is_a?(::Hash)

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

Instance Method Details

#valueObject



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

def value
  target.map do |item|
    field_class = Registry.fetch(self.class.item_class[item.class])

    field = field_class.new(ast_node, item, variables, context)
    field.value
  end
end