class Logux::Process::Batch

Attributes

batch[R]
stream[R]

Public Class Methods

new(stream:, batch:) click to toggle source
# File lib/logux/process/batch.rb, line 8
def initialize(stream:, batch:)
  @stream = stream
  @batch = batch
end

Public Instance Methods

call() click to toggle source
# File lib/logux/process/batch.rb, line 13
def call
  last_chunk = batch.size - 1
  preprocessed_batch.map.with_index do |chunk, index|
    case chunk[:type]
    when :action
      process_action(chunk: chunk.slice(:action, :meta))
    when :auth
      process_auth(chunk: chunk[:auth])
    end
    stream.write(',') if index != last_chunk
  end
end
preprocess_action(chunk) click to toggle source
# File lib/logux/process/batch.rb, line 45
def preprocess_action(chunk)
  { type: :action,
    action: Logux::Action.new(chunk[1]),
    meta: Logux::Meta.new(chunk[2]) }
end
preprocess_auth(chunk) click to toggle source
# File lib/logux/process/batch.rb, line 51
def preprocess_auth(chunk)
  { type: :auth,
    auth: Logux::Auth.new(user_id: chunk[1],
                          credentials: chunk[2],
                          auth_id: chunk[3]) }
end
preprocessed_batch() click to toggle source
# File lib/logux/process/batch.rb, line 34
def preprocessed_batch
  @preprocessed_batch ||= batch.map do |chunk|
    case chunk[0]
    when 'action'
      preprocess_action(chunk)
    when 'auth'
      preprocess_auth(chunk)
    end
  end
end
process_action(chunk:) click to toggle source
# File lib/logux/process/batch.rb, line 26
def process_action(chunk:)
  Logux::Process::Action.new(stream: stream, chunk: chunk).call
end
process_auth(chunk:) click to toggle source
# File lib/logux/process/batch.rb, line 30
def process_auth(chunk:)
  Logux::Process::Auth.new(stream: stream, chunk: chunk).call
end