Class: Rails::GraphQL::Helpers::InheritedCollection::Base

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rails/graphql/helpers/inherited_collection/base.rb

Overview

The base class for inherited collections. It helps softly dealing with values defined in multiple class instance variables and look up the tree to make it possible to iterate over combined result

Direct Known Subclasses

Array, Hash

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, ivar, type) ⇒ Base

Returns a new instance of Base.



18
19
20
21
22
# File 'lib/rails/graphql/helpers/inherited_collection/base.rb', line 18

def initialize(source, ivar, type)
  @source = source
  @ivar = ivar
  @type = type
end

Class Method Details

.handle(source, ivar, type) ⇒ Object

Just a little helper to initialize the iterator form a given source



13
14
15
16
# File 'lib/rails/graphql/helpers/inherited_collection/base.rb', line 13

def self.handle(source, ivar, type)
  klass = (type == :array || type == :set) ? :Array : :Hash
  InheritedCollection.const_get(klass, false).new(source, ivar, type)
end

Instance Method Details

#lazyObject

Overrides the lazy enumerator because each instance variable defined and found by the each_definition will be iterated over lazily



26
27
28
# File 'lib/rails/graphql/helpers/inherited_collection/base.rb', line 26

def lazy
  Enumerator::Lazy.new(each_definition) { |y, d| d.each(&y) }
end