lib/kamerling/receiver.rb in kamerling-0.0.2 vs lib/kamerling/receiver.rb in kamerling-0.0.3

- old
+ new

@@ -1,11 +1,39 @@ -module Kamerling class Receiver - def receive addr: req(:addr), client_uuid: req(:client_uuid), - data: req(:data), repos: Repos, task_uuid: req(:task_uuid) - client = repos[Client][client_uuid] - task = repos[Task][task_uuid] - result = Result.new addr: addr, client: client, data: data, task: task - client.busy = false - task.done = true - repos << result << client << task +require_relative 'client' +require_relative 'repos' +require_relative 'result' +require_relative 'task' + +module Kamerling + class Receiver + def self.receive(addr:, message:, repos: Repos) + new(addr: addr, message: message, repos: repos).receive + end + + def initialize(addr:, message:, repos:) + @addr, @message, @repos = addr, message, repos + end + + def receive + client.busy = false + task.done = true + repos << result << client << task + end + + attr_reader :addr, :message, :repos + private :addr, :message, :repos + + private + + def client + @client ||= repos[Client][message.client_uuid] + end + + def result + Result.new(addr: addr, client: client, data: message.payload, task: task) + end + + def task + @task ||= repos[Task][message.task_uuid] + end end -end end +end