From 0c1cc529dc759c9b120fee1c2c6705b69de69b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Wed, 22 Nov 2023 12:54:46 +0100 Subject: [PATCH] Refactor Co-authored-by: Szymon Fiedler Co-authored-by: Piotr Jurewicz --- .../lib/project_management/command_handler.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/decider/lib/project_management/command_handler.rb b/examples/decider/lib/project_management/command_handler.rb index 99293d0..decf771 100644 --- a/examples/decider/lib/project_management/command_handler.rb +++ b/examples/decider/lib/project_management/command_handler.rb @@ -1,6 +1,10 @@ module ProjectManagement class CommandHandler - def initialize(event_store) = @event_store = event_store + def initialize(event_store) + @event_store = event_store + @decider = Issue + end + def handle(cmd) state, version = @@ -8,12 +12,12 @@ def handle(cmd) .read .stream(stream_name(cmd.id)) .reduce( - [Issue.initial_state(cmd.id), -1] + [@decider.initial_state(cmd.id), -1] ) do |(state, version), event| - [Issue.evolve(state, event), version + 1] + [@decider.evolve(state, event), version + 1] end - case result = Issue.decide(cmd, state) + case result = @decider.decide(cmd, state) when StandardError raise Error else