lib/kamerling/handler.rb in kamerling-0.0.1 vs lib/kamerling/handler.rb in kamerling-0.0.2
- old
+ new
@@ -4,21 +4,26 @@
def initialize receiver: Receiver.new, registrar: Registrar.new
@receiver, @registrar = receiver, registrar
end
def handle input, addr
- message = Message.new input
+ 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
+ project_uuid: message.project_uuid
when :RSLT
receiver.receive addr: addr, client_uuid: message.client_uuid,
- data: message.payload, task_uuid: message.task_uuid
+ data: message.payload, task_uuid: message.task_uuid
end
- rescue Message::UnknownType => exception
- raise UnknownInput, exception.message
end
-
- attr_reader :receiver, :registrar
- private :receiver, :registrar
end end