Module: Serega::SeregaBatch::AttributeLoader::InstanceMethods
- Included in:
- Serega::SeregaBatch::AttributeLoader
- Defined in:
- lib/serega/batch/attribute_loader.rb
Overview
Instance methods for AttributeLoader
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#point ⇒ Object
readonly
Returns the value of attribute point.
Instance Method Summary collapse
-
#attach(batches) ⇒ void
Attaches already loaded batch values to every stored object.
- #initialize(point, level) ⇒ Object
-
#load_batch(loader) ⇒ Object
Loads a single named batch for this level's objects.
-
#preload_associations ⇒ void
Preloads this attribute's associations onto the level's objects, once for the attribute (not per named batch loader), via the serializer's registered
preload_withhandler. -
#store(object, attacher) ⇒ void
Stores object with attacher to find and attach attribute values in batch later.
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
71 72 73 |
# File 'lib/serega/batch/attribute_loader.rb', line 71 def level @level end |
#point ⇒ Object (readonly)
Returns the value of attribute point.
70 71 72 |
# File 'lib/serega/batch/attribute_loader.rb', line 70 def point @point end |
Instance Method Details
#attach(batches) ⇒ void
This method returns an undefined value.
Attaches already loaded batch values to every stored object. Value resolution happens here (inside the attacher), so errors are annotated with the attribute, matching the synchronous walk.
62 63 64 65 66 67 68 |
# File 'lib/serega/batch/attribute_loader.rb', line 62 def attach(batches) serialized_object_attachers.each do |object, attacher| attacher.call(object, batches) end rescue => error SeregaUtils::SerializedAttributeError.call(error, point) end |
#initialize(point, level) ⇒ Object
14 15 16 17 18 |
# File 'lib/serega/batch/attribute_loader.rb', line 14 def initialize(point, level) @point = point @level = level @serialized_object_attachers = [] end |
#load_batch(loader) ⇒ Object
Loads a single named batch for this level's objects. Caching across attributes that reuse the loader is handled by the Level.
51 52 53 54 55 |
# File 'lib/serega/batch/attribute_loader.rb', line 51 def load_batch(loader) level.load(loader) rescue => error SeregaUtils::SerializedAttributeError.call(error, point) end |
#preload_associations ⇒ void
This method returns an undefined value.
Preloads this attribute's associations onto the level's objects, once for
the attribute (not per named batch loader), via the serializer's registered
preload_with handler. Raises when :preload is declared but no handler
exists, so a declared preload never silently does nothing.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/serega/batch/attribute_loader.rb', line 33 def preload_associations preloads = point.attribute.preloads return unless preloads handler = point.class.serializer_class.preload_with unless handler raise SeregaError, "The :preload option requires a preload handler. Register one with `preload_with` (the :activerecord_preloads plugin does this for you)." end handler.call(level.objects, preloads) rescue => error SeregaUtils::SerializedAttributeError.call(error, point) end |
#store(object, attacher) ⇒ void
This method returns an undefined value.
Stores object with attacher to find and attach attribute values in batch later.
24 25 26 |
# File 'lib/serega/batch/attribute_loader.rb', line 24 def store(object, attacher) serialized_object_attachers << [object, attacher] end |