Module: Serega::SeregaBatch::Loader::InstanceMethods

Included in:
Serega::SeregaBatch::Loader
Defined in:
lib/serega/batch/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



26
27
28
# File 'lib/serega/batch/loader.rb', line 26

def block
  @block
end

#initialsHash (readonly)

BatchLoader initial params

Returns:

  • (Hash)

    BatchLoader initial params



18
19
20
# File 'lib/serega/batch/loader.rb', line 18

def initials
  @initials
end

#nameSymbol (readonly)

BatchLoader name

Returns:

  • (Symbol)

    BatchLoader name



22
23
24
# File 'lib/serega/batch/loader.rb', line 22

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



34
35
36
37
38
39
40
41
42
# File 'lib/serega/batch/loader.rb', line 34

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



48
49
50
51
52
53
54
# File 'lib/serega/batch/loader.rb', line 48

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