lib/kamerling/handler.rb in kamerling-0.0.2 vs lib/kamerling/handler.rb in kamerling-0.0.3
- old
+ new
@@ -1,29 +1,20 @@
-module Kamerling class Handler
- UnknownInput = Class.new RuntimeError
+require_relative 'receiver'
+require_relative 'registrar'
- def initialize receiver: Receiver.new, registrar: Registrar.new
- @receiver, @registrar = receiver, registrar
- end
+module Kamerling
+ class Handler
+ def initialize(receiver: Receiver, registrar: Registrar)
+ @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
+ def handle(message, addr)
+ case message.type
+ when :RGST then registrar.register addr: addr, message: message
+ when :RSLT then receiver.receive addr: addr, message: message
+ end
end
+
+ attr_reader :receiver, :registrar
+ private :receiver, :registrar
end
-end end
+end