Class: Serega::SeregaBatch::Level
- Inherits:
-
Object
- Object
- Serega::SeregaBatch::Level
- Defined in:
- lib/serega/batch/level.rb
Overview
Objects serialized at one plan level, together with their loaded batch results.
Every attribute serialized at the same level shares one Level, so a named batch loader reused by several of them runs once for the whole set of objects. The same loader over a different level (deeper nesting) uses a different Level and loads again.
Instance Attribute Summary collapse
-
#objects ⇒ Array
readonly
Objects gathered for this level.
Instance Method Summary collapse
-
#add_objects(objects) ⇒ void
Adds a chunk of serialized objects to this level.
-
#initialize(context) ⇒ Level
constructor
A new instance of Level.
-
#load(loader) ⇒ Object
Loads and returns values for the given batch loader, once per loader.
Constructor Details
#initialize(context) ⇒ Level
Returns a new instance of Level.
21 22 23 24 25 |
# File 'lib/serega/batch/level.rb', line 21 def initialize(context) @context = context @objects = [] @results = {}.compare_by_identity end |
Instance Attribute Details
#objects ⇒ Array (readonly)
Returns Objects gathered for this level.
18 19 20 |
# File 'lib/serega/batch/level.rb', line 18 def objects @objects end |
Instance Method Details
#add_objects(objects) ⇒ void
This method returns an undefined value.
Adds a chunk of serialized objects to this level.
30 31 32 |
# File 'lib/serega/batch/level.rb', line 30 def add_objects(objects) @objects.concat(objects) end |
#load(loader) ⇒ Object
Loads and returns values for the given batch loader, once per loader.
Freezes the gathered objects on the first load: all of a level's objects
are added before any of its batches load, so sealing the set here guards
against a later stray add_objects and against a loader mutating it.
42 43 44 45 |
# File 'lib/serega/batch/level.rb', line 42 def load(loader) @objects.freeze @results[loader] ||= loader.load(@objects, @context) end |