Sha256: 073a8dad76a6798d99def7f39488338f36b2d9254f736d4050d065d47dde2af2

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

module Kamerling class Handler
  UnknownInput = Class.new RuntimeError

  def initialize receiver: Receiver.new, registrar: Registrar.new
    @receiver, @registrar = receiver, registrar
  end

  def handle input, addr
    process Message.new(input), addr
  rescue Message::UnknownType => exception
    raise UnknownInput, exception.message
  end

  attr_reader :receiver, :registrar
  private     :receiver, :registrar

  private

  def process message, addr
    case message.type
    when :RGST
      registrar.register addr: addr, client_uuid: message.client_uuid,
                         project_uuid: message.project_uuid
    when :RSLT
      receiver.receive addr: addr, client_uuid: message.client_uuid,
                       data: message.payload, task_uuid: message.task_uuid
    end
  end
end end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kamerling-0.0.2 lib/kamerling/handler.rb