Module: Serega::SeregaEngine::Loader::InstanceMethods

Included in:
Serega::SeregaEngine::Loader
Defined in:
lib/serega/engine/loader.rb

Overview

BatchLoader instance methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#block#call (readonly)

BatchLoader block

Returns:

  • (#call)

    BatchLoader block



29
30
31
# File 'lib/serega/engine/loader.rb', line 29

def block
  @block
end

#initialsHash (readonly)

BatchLoader initial params

Returns:

  • (Hash)

    BatchLoader initial params



21
22
23
# File 'lib/serega/engine/loader.rb', line 21

def initials
  @initials
end

#nameSymbol (readonly)

BatchLoader name

Returns:

  • (Symbol)

    BatchLoader name



25
26
27
# File 'lib/serega/engine/loader.rb', line 25

def name
  @name
end

Instance Method Details

#initialize(name:, block:) ⇒ Object

Initializes new batch loader

Parameters:

  • name (Symbol, String)

    Name of attribute

  • block (#call)

    BatchLoader block



37
38
39
40
41
42
43
44
45
# File 'lib/serega/engine/loader.rb', line 37

def initialize(name:, block:)
  serializer_class = self.class.serializer_class
  serializer_class::CheckBatchLoaderParams.new(name, block).validate

  @initials = SeregaUtils::EnumDeepFreeze.call(name: name, block: block)
  @name = name.to_sym
  @block = block
  @signature = SeregaUtils::MethodSignature.call(block, pos_limit: 2, keyword_args: [:ctx])
end

#load(objects, context) ⇒ void

This method returns an undefined value.

Serializes values for objects

Parameters:

  • objects (Array)

    Serialized objects

  • context (Hash)

    Serialization context



51
52
53
54
55
56
57
# File 'lib/serega/engine/loader.rb', line 51

def load(objects, context)
  case signature
  when "1" then block.call(objects)
  when "2" then block.call(objects, context)
  else block.call(objects, ctx: context) # "1_ctx"
  end
end