Class: Rails::GraphQL::Helpers::InheritedCollection::Base
- Inherits:
-
Object
- Object
- Rails::GraphQL::Helpers::InheritedCollection::Base
- 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
Class Method Summary collapse
-
.handle(source, ivar, type) ⇒ Object
Just a little helper to initialize the iterator form a given
source
.
Instance Method Summary collapse
-
#initialize(source, ivar, type) ⇒ Base
constructor
A new instance of Base.
-
#lazy ⇒ Object
Overrides the lazy enumerator because each instance variable defined and found by the
each_definition
will be iterated over lazily.
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
#lazy ⇒ Object
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 |