Module: Serega::SeregaPlanPoint::InstanceMethods
- Included in:
- Serega::SeregaPlanPoint
- Defined in:
- lib/serega/plan_point.rb
Overview
SeregaPlanPoint instance methods
Instance Attribute Summary collapse
-
#attribute ⇒ SeregaAttribute
readonly
Shows current attribute.
-
#child_plan ⇒ SeregaPlan?
readonly
Shows child plan if exists.
-
#modifiers ⇒ Hash
readonly
Child fields to serialize.
-
#plan ⇒ SeregaAttribute
readonly
Link to current plan this point belongs to.
Instance Method Summary collapse
-
#batch_loaders ⇒ Object
Attribute
batch_loaders. -
#child_object_serializer ⇒ Class<SeregaObjectSerializer>
Object serializer class for child plan.
-
#child_serializer(context:, **opts) ⇒ SeregaObjectSerializer?
Builds the object serializer that serializes this point's relation, or nil when the point has no child plan (a plain attribute).
-
#initialize(plan, attribute, modifiers = nil) ⇒ SeregaPlanPoint
Initializes plan point.
-
#load_batches(level) ⇒ Hash?
Loads the batch loaders this point's value needs, each once for the whole level, and returns them keyed by loader name for #value to read from.
-
#many ⇒ Object
Attribute
manyoption. -
#name ⇒ Object
Attribute
name. -
#preloads ⇒ Object
Attribute
preloads. -
#run_preloads(objects) ⇒ void
Runs this point's declared preloads over the given objects using the serializer's registered preload handler.
-
#serializer ⇒ Object
Attribute
serializeroption. -
#value(obj, ctx, batches: nil) ⇒ Object
Attribute
value.
Instance Attribute Details
#attribute ⇒ SeregaAttribute (readonly)
Shows current attribute
20 21 22 |
# File 'lib/serega/plan_point.rb', line 20 def attribute @attribute end |
#child_plan ⇒ SeregaPlan? (readonly)
Shows child plan if exists
24 25 26 |
# File 'lib/serega/plan_point.rb', line 24 def child_plan @child_plan end |
#modifiers ⇒ Hash (readonly)
Child fields to serialize
28 29 30 |
# File 'lib/serega/plan_point.rb', line 28 def modifiers @modifiers end |
#plan ⇒ SeregaAttribute (readonly)
Link to current plan this point belongs to
16 17 18 |
# File 'lib/serega/plan_point.rb', line 16 def plan @plan end |
Instance Method Details
#batch_loaders ⇒ Object
Attribute batch_loaders
75 76 77 |
# File 'lib/serega/plan_point.rb', line 75 def batch_loaders attribute.batch_loaders end |
#child_object_serializer ⇒ Class<SeregaObjectSerializer>
Returns object serializer class for child plan.
123 124 125 |
# File 'lib/serega/plan_point.rb', line 123 def child_object_serializer serializer::SeregaObjectSerializer end |
#child_serializer(context:, **opts) ⇒ SeregaObjectSerializer?
Builds the object serializer that serializes this point's relation, or nil
when the point has no child plan (a plain attribute). The point owns the
static config (child plan, serializer class, many); the caller injects the
runtime context and opts.
135 136 137 138 139 |
# File 'lib/serega/plan_point.rb', line 135 def child_serializer(context:, **opts) return unless child_plan child_object_serializer.new(context: context, plan: child_plan, many: many, **opts) end |
#initialize(plan, attribute, modifiers = nil) ⇒ SeregaPlanPoint
Initializes plan point
42 43 44 45 46 47 |
# File 'lib/serega/plan_point.rb', line 42 def initialize(plan, attribute, modifiers = nil) @plan = plan @attribute = attribute @modifiers = modifiers set_normalized_vars end |
#load_batches(level) ⇒ Hash?
Loads the batch loaders this point's value needs, each once for the whole level, and returns them keyed by loader name for #value to read from.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/serega/plan_point.rb', line 108 def load_batches(level) names = batch_loaders return if names.empty? loaders = self.class.serializer_class.batch_loaders names.each_with_object({}) do |name, batches| batches[name] = level.fetch(loaders[name]) end rescue => error SeregaUtils::SerializedAttributeError.call(error, self) end |
#many ⇒ Object
Attribute many option
63 64 65 |
# File 'lib/serega/plan_point.rb', line 63 def many attribute.many end |
#name ⇒ Object
Attribute name
57 58 59 |
# File 'lib/serega/plan_point.rb', line 57 def name attribute.name end |
#preloads ⇒ Object
Attribute preloads
81 82 83 |
# File 'lib/serega/plan_point.rb', line 81 def preloads attribute.preloads end |
#run_preloads(objects) ⇒ void
This method returns an undefined value.
Runs this point's declared preloads over the given objects using the serializer's registered preload handler.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/serega/plan_point.rb', line 90 def run_preloads(objects) return unless preloads handler = self.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(objects, preloads) rescue => error SeregaUtils::SerializedAttributeError.call(error, self) end |
#serializer ⇒ Object
Attribute serializer option
69 70 71 |
# File 'lib/serega/plan_point.rb', line 69 def serializer attribute.serializer end |
#value(obj, ctx, batches: nil) ⇒ Object
Attribute value
51 52 53 |
# File 'lib/serega/plan_point.rb', line 51 def value(obj, ctx, batches: nil) attribute.value(obj, ctx, batches: batches) end |