From 2117af095c4c2ece45506f79a79a8e88a3629a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Thu, 21 Nov 2024 00:11:25 +0100 Subject: [PATCH] More formatting --- examples/actor_like/Gemfile | 1 + .../actor_like/lib/aggregate_repository.rb | 1 + examples/actor_like/lib/aggregate_root.rb | 3 +- examples/actor_like/lib/aggregate_state.rb | 3 +- examples/actor_like/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 1 + .../lib/project_management/issue_state.rb | 1 + examples/actor_like/test/issue_test.rb | 7 ++-- examples/aggregate_root/Gemfile | 1 + .../aggregate_root/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 7 ++++ .../lib/project_management/repository.rb | 1 + examples/aggregate_root/test/issue_test.rb | 7 ++-- examples/decider/Gemfile | 1 + examples/decider/lib/project_management.rb | 1 + .../decider/lib/project_management/handler.rb | 1 + .../decider/lib/project_management/issue.rb | 1 + .../lib/project_management/repository.rb | 1 + examples/decider/test/issue_test.rb | 7 ++-- examples/document_way/Gemfile | 1 + .../document_way/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 7 ++++ .../lib/project_management/repository.rb | 1 + examples/document_way/test/issue_test.rb | 7 ++-- examples/duck_typing/Gemfile | 1 + .../duck_typing/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 1 + .../lib/project_management/repository.rb | 1 + .../duck_typing/lib/project_management/ui.rb | 1 + examples/duck_typing/test/issue_test.rb | 7 ++-- examples/extracted_state/Gemfile | 1 + .../extracted_state/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 7 ++++ .../lib/project_management/issue_state.rb | 1 + .../lib/project_management/repository.rb | 1 + examples/extracted_state/test/issue_test.rb | 7 ++-- examples/functional/Gemfile | 1 + examples/functional/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 1 + .../lib/project_management/issue_state.rb | 1 + .../lib/project_management/repository.rb | 1 + examples/functional/test/issue_test.rb | 7 ++-- examples/polymorphic/Gemfile | 1 + .../polymorphic/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 30 ++++++++++++++++ examples/polymorphic/test/issue_test.rb | 7 ++-- examples/poro/Gemfile | 1 + examples/poro/lib/project_management.rb | 1 + .../poro/lib/project_management/handler.rb | 1 + examples/poro/lib/project_management/issue.rb | 1 + .../project_management/issue_projection.rb | 1 + examples/poro/test/issue_test.rb | 7 ++-- examples/query_based/Gemfile | 1 + .../query_based/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 7 ++++ .../lib/project_management/issue.rb | 1 + .../project_management/issue_projection.rb | 1 + .../lib/project_management/repository.rb | 3 +- examples/query_based/test/issue_test.rb | 7 ++-- examples/rails_way/Gemfile | 1 + examples/rails_way/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../rails_way/lib/project_management/issue.rb | 1 + examples/rails_way/test/issue_test.rb | 7 ++-- examples/repository/Gemfile | 1 + examples/repository/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 1 + .../lib/project_management/repository.rb | 1 + examples/repository/test/issue_test.rb | 7 ++-- examples/roles/Gemfile | 1 + examples/roles/lib/project_management.rb | 1 + .../roles/lib/project_management/handler.rb | 35 ++++++++++--------- .../roles/lib/project_management/issue.rb | 1 + examples/roles/test/issue_test.rb | 7 ++-- examples/yield_based/Gemfile | 1 + .../yield_based/lib/aggregate_repository.rb | 1 + examples/yield_based/lib/aggregate_root.rb | 3 +- .../yield_based/lib/project_management.rb | 1 + .../lib/project_management/handler.rb | 1 + .../lib/project_management/issue.rb | 1 + examples/yield_based/test/issue_test.rb | 7 ++-- shared/lib/project_management.rb | 1 + shared/lib/project_management/commands.rb | 1 + shared/lib/project_management/errors.rb | 1 + shared/lib/project_management/events.rb | 2 ++ shared/lib/project_management/test.rb | 1 + 94 files changed, 211 insertions(+), 63 deletions(-) diff --git a/examples/actor_like/Gemfile b/examples/actor_like/Gemfile index dfa2991..b1c8640 100644 --- a/examples/actor_like/Gemfile +++ b/examples/actor_like/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/actor_like/lib/aggregate_repository.rb b/examples/actor_like/lib/aggregate_repository.rb index b4e3e60..9da6e98 100644 --- a/examples/actor_like/lib/aggregate_repository.rb +++ b/examples/actor_like/lib/aggregate_repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class AggregateRepository def initialize(event_store) @event_store = event_store diff --git a/examples/actor_like/lib/aggregate_root.rb b/examples/actor_like/lib/aggregate_root.rb index 4c111a5..84271bd 100644 --- a/examples/actor_like/lib/aggregate_root.rb +++ b/examples/actor_like/lib/aggregate_root.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module AggregateRoot module ClassMethods def on(*event_klasses, &block) event_klasses.each do |event_klass| name = event_klass.name || - raise(ArgumentError, "Anonymous class is missing name") + raise(ArgumentError, "Anonymous class is missing name") handler_name = "on_#{name}" define_method(handler_name, &block) @on_methods ||= {} diff --git a/examples/actor_like/lib/aggregate_state.rb b/examples/actor_like/lib/aggregate_state.rb index 6ffdf39..c599498 100644 --- a/examples/actor_like/lib/aggregate_state.rb +++ b/examples/actor_like/lib/aggregate_state.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module AggregateState module ClassMethods def on(*event_klasses, &block) event_klasses.each do |event_klass| name = event_klass.name || - raise(ArgumentError, "Anonymous class is missing name") + raise(ArgumentError, "Anonymous class is missing name") handler_name = "on_#{name}" define_method(handler_name, &block) @on_methods ||= {} diff --git a/examples/actor_like/lib/project_management.rb b/examples/actor_like/lib/project_management.rb index d7dda9a..f51b12b 100644 --- a/examples/actor_like/lib/project_management.rb +++ b/examples/actor_like/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "aggregate_state" require_relative "aggregate_root" diff --git a/examples/actor_like/lib/project_management/handler.rb b/examples/actor_like/lib/project_management/handler.rb index 7f4e939..906dc80 100644 --- a/examples/actor_like/lib/project_management/handler.rb +++ b/examples/actor_like/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/actor_like/lib/project_management/issue.rb b/examples/actor_like/lib/project_management/issue.rb index 0a43163..52ddf2a 100644 --- a/examples/actor_like/lib/project_management/issue.rb +++ b/examples/actor_like/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue include AggregateRoot diff --git a/examples/actor_like/lib/project_management/issue_state.rb b/examples/actor_like/lib/project_management/issue_state.rb index 8221855..cd0383f 100644 --- a/examples/actor_like/lib/project_management/issue_state.rb +++ b/examples/actor_like/lib/project_management/issue_state.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class IssueState < Struct.new(:id, :status) include AggregateState diff --git a/examples/actor_like/test/issue_test.rb b/examples/actor_like/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/actor_like/test/issue_test.rb +++ b/examples/actor_like/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/aggregate_root/Gemfile b/examples/aggregate_root/Gemfile index c23ccf6..0356b4c 100644 --- a/examples/aggregate_root/Gemfile +++ b/examples/aggregate_root/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/aggregate_root/lib/project_management.rb b/examples/aggregate_root/lib/project_management.rb index 82a1b94..b04d317 100644 --- a/examples/aggregate_root/lib/project_management.rb +++ b/examples/aggregate_root/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "aggregate_root" require_relative "../../../shared/lib/project_management" diff --git a/examples/aggregate_root/lib/project_management/handler.rb b/examples/aggregate_root/lib/project_management/handler.rb index e1b14e2..0151f20 100644 --- a/examples/aggregate_root/lib/project_management/handler.rb +++ b/examples/aggregate_root/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/aggregate_root/lib/project_management/issue.rb b/examples/aggregate_root/lib/project_management/issue.rb index dedb8c7..896fab5 100644 --- a/examples/aggregate_root/lib/project_management/issue.rb +++ b/examples/aggregate_root/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue include AggregateRoot @@ -11,31 +12,37 @@ def initialize(id) def open fail if @status + apply(IssueOpened.new(data: { issue_id: @id })) end def resolve fail unless %i[open in_progress reopened].include? @status + apply(IssueResolved.new(data: { issue_id: @id })) end def close fail unless %i[open in_progress resolved reopened].include? @status + apply(IssueClosed.new(data: { issue_id: @id })) end def reopen fail unless %i[resolved closed].include? @status + apply(IssueReopened.new(data: { issue_id: @id })) end def start fail unless %i[open reopened].include? @status + apply(IssueProgressStarted.new(data: { issue_id: @id })) end def stop fail unless %i[in_progress].include? @status + apply(IssueProgressStopped.new(data: { issue_id: @id })) end diff --git a/examples/aggregate_root/lib/project_management/repository.rb b/examples/aggregate_root/lib/project_management/repository.rb index 7d5df21..f93d331 100644 --- a/examples/aggregate_root/lib/project_management/repository.rb +++ b/examples/aggregate_root/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement Repository = AggregateRoot::Repository end diff --git a/examples/aggregate_root/test/issue_test.rb b/examples/aggregate_root/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/aggregate_root/test/issue_test.rb +++ b/examples/aggregate_root/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/decider/Gemfile b/examples/decider/Gemfile index dfa2991..b1c8640 100644 --- a/examples/decider/Gemfile +++ b/examples/decider/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/decider/lib/project_management.rb b/examples/decider/lib/project_management.rb index acb6344..77e09d7 100644 --- a/examples/decider/lib/project_management.rb +++ b/examples/decider/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/handler" require_relative "project_management/issue" diff --git a/examples/decider/lib/project_management/handler.rb b/examples/decider/lib/project_management/handler.rb index c0e35ee..22bcf18 100644 --- a/examples/decider/lib/project_management/handler.rb +++ b/examples/decider/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/decider/lib/project_management/issue.rb b/examples/decider/lib/project_management/issue.rb index 6ad54fb..cfb7675 100644 --- a/examples/decider/lib/project_management/issue.rb +++ b/examples/decider/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement module Issue InvalidTransition = Class.new(StandardError) diff --git a/examples/decider/lib/project_management/repository.rb b/examples/decider/lib/project_management/repository.rb index 7e199cc..a13a092 100644 --- a/examples/decider/lib/project_management/repository.rb +++ b/examples/decider/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository def initialize(event_store) diff --git a/examples/decider/test/issue_test.rb b/examples/decider/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/decider/test/issue_test.rb +++ b/examples/decider/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/document_way/Gemfile b/examples/document_way/Gemfile index 3971904..1871cad 100644 --- a/examples/document_way/Gemfile +++ b/examples/document_way/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/document_way/lib/project_management.rb b/examples/document_way/lib/project_management.rb index 8fb934b..709d081 100644 --- a/examples/document_way/lib/project_management.rb +++ b/examples/document_way/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_record" require_relative "../../../shared/lib/project_management" diff --git a/examples/document_way/lib/project_management/handler.rb b/examples/document_way/lib/project_management/handler.rb index dfbf34a..51460f7 100644 --- a/examples/document_way/lib/project_management/handler.rb +++ b/examples/document_way/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/document_way/lib/project_management/issue.rb b/examples/document_way/lib/project_management/issue.rb index 377c3b6..5e620ba 100644 --- a/examples/document_way/lib/project_management/issue.rb +++ b/examples/document_way/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue InvalidTransition = Class.new(StandardError) @@ -11,36 +12,42 @@ def initialize(state) def open fail if state.status + state.status = "open" IssueOpened.new(data: { issue_id: state.id }) end def resolve fail unless %w[open in_progress reopened].include? state.status + state.status = "resolved" IssueResolved.new(data: { issue_id: state.id }) end def close fail unless %w[open in_progress resolved reopened].include? state.status + state.status = "closed" IssueClosed.new(data: { issue_id: state.id }) end def reopen fail unless %w[resolved closed].include? state.status + state.status = "reopened" IssueReopened.new(data: { issue_id: state.id }) end def start fail unless %w[open reopened].include? state.status + state.status = "in_progress" IssueProgressStarted.new(data: { issue_id: state.id }) end def stop fail unless %w[in_progress].include? state.status + state.status = "open" IssueProgressStopped.new(data: { issue_id: state.id }) end diff --git a/examples/document_way/lib/project_management/repository.rb b/examples/document_way/lib/project_management/repository.rb index 6d58678..9903bc8 100644 --- a/examples/document_way/lib/project_management/repository.rb +++ b/examples/document_way/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository class Record < ActiveRecord::Base diff --git a/examples/document_way/test/issue_test.rb b/examples/document_way/test/issue_test.rb index 2ce4303..4b074c9 100644 --- a/examples/document_way/test/issue_test.rb +++ b/examples/document_way/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" diff --git a/examples/duck_typing/Gemfile b/examples/duck_typing/Gemfile index eefe228..5d9f8b1 100644 --- a/examples/duck_typing/Gemfile +++ b/examples/duck_typing/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/duck_typing/lib/project_management.rb b/examples/duck_typing/lib/project_management.rb index f493d15..84ea275 100644 --- a/examples/duck_typing/lib/project_management.rb +++ b/examples/duck_typing/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "tty-prompt" require_relative "../../../shared/lib/project_management" diff --git a/examples/duck_typing/lib/project_management/handler.rb b/examples/duck_typing/lib/project_management/handler.rb index d53b6c5..682004d 100644 --- a/examples/duck_typing/lib/project_management/handler.rb +++ b/examples/duck_typing/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/duck_typing/lib/project_management/issue.rb b/examples/duck_typing/lib/project_management/issue.rb index e71894f..3d31020 100644 --- a/examples/duck_typing/lib/project_management/issue.rb +++ b/examples/duck_typing/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue def open = Open.new diff --git a/examples/duck_typing/lib/project_management/repository.rb b/examples/duck_typing/lib/project_management/repository.rb index 58d678e..0f60203 100644 --- a/examples/duck_typing/lib/project_management/repository.rb +++ b/examples/duck_typing/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository def initialize(event_store) diff --git a/examples/duck_typing/lib/project_management/ui.rb b/examples/duck_typing/lib/project_management/ui.rb index 35d383f..c565d95 100644 --- a/examples/duck_typing/lib/project_management/ui.rb +++ b/examples/duck_typing/lib/project_management/ui.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class UI def initialize diff --git a/examples/duck_typing/test/issue_test.rb b/examples/duck_typing/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/duck_typing/test/issue_test.rb +++ b/examples/duck_typing/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/extracted_state/Gemfile b/examples/extracted_state/Gemfile index dfa2991..b1c8640 100644 --- a/examples/extracted_state/Gemfile +++ b/examples/extracted_state/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/extracted_state/lib/project_management.rb b/examples/extracted_state/lib/project_management.rb index 8f020c9..b258247 100644 --- a/examples/extracted_state/lib/project_management.rb +++ b/examples/extracted_state/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/handler" require_relative "project_management/issue" diff --git a/examples/extracted_state/lib/project_management/handler.rb b/examples/extracted_state/lib/project_management/handler.rb index 76c1945..1d7c8d1 100644 --- a/examples/extracted_state/lib/project_management/handler.rb +++ b/examples/extracted_state/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/extracted_state/lib/project_management/issue.rb b/examples/extracted_state/lib/project_management/issue.rb index 55dd381..eee86f9 100644 --- a/examples/extracted_state/lib/project_management/issue.rb +++ b/examples/extracted_state/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue InvalidTransition = Class.new(StandardError) @@ -12,31 +13,37 @@ def initialize(state) def open fail if @state.status + changes << IssueOpened.new(data: { issue_id: @state.id }) end def resolve fail unless %i[open in_progress reopened].include? @state.status + changes << IssueResolved.new(data: { issue_id: @state.id }) end def close fail unless %i[open in_progress resolved reopened].include? @state.status + changes << IssueClosed.new(data: { issue_id: @state.id }) end def reopen fail unless %i[resolved closed].include? @state.status + changes << IssueReopened.new(data: { issue_id: @state.id }) end def start fail unless %i[open reopened].include? @state.status + changes << IssueProgressStarted.new(data: { issue_id: @state.id }) end def stop fail unless %i[in_progress].include? @state.status + changes << IssueProgressStopped.new(data: { issue_id: @state.id }) end diff --git a/examples/extracted_state/lib/project_management/issue_state.rb b/examples/extracted_state/lib/project_management/issue_state.rb index 9c241c0..7ab0464 100644 --- a/examples/extracted_state/lib/project_management/issue_state.rb +++ b/examples/extracted_state/lib/project_management/issue_state.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement IssueState = Data.define(:id, :status) do diff --git a/examples/extracted_state/lib/project_management/repository.rb b/examples/extracted_state/lib/project_management/repository.rb index 91b3ccf..048a5a7 100644 --- a/examples/extracted_state/lib/project_management/repository.rb +++ b/examples/extracted_state/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository def initialize(event_store) diff --git a/examples/extracted_state/test/issue_test.rb b/examples/extracted_state/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/extracted_state/test/issue_test.rb +++ b/examples/extracted_state/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/functional/Gemfile b/examples/functional/Gemfile index dfa2991..b1c8640 100644 --- a/examples/functional/Gemfile +++ b/examples/functional/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/functional/lib/project_management.rb b/examples/functional/lib/project_management.rb index 8f020c9..b258247 100644 --- a/examples/functional/lib/project_management.rb +++ b/examples/functional/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/handler" require_relative "project_management/issue" diff --git a/examples/functional/lib/project_management/handler.rb b/examples/functional/lib/project_management/handler.rb index 0c7b70d..452d7ae 100644 --- a/examples/functional/lib/project_management/handler.rb +++ b/examples/functional/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/functional/lib/project_management/issue.rb b/examples/functional/lib/project_management/issue.rb index 9a6e63d..129d5da 100644 --- a/examples/functional/lib/project_management/issue.rb +++ b/examples/functional/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement module Issue InvalidTransition = Class.new(StandardError) diff --git a/examples/functional/lib/project_management/issue_state.rb b/examples/functional/lib/project_management/issue_state.rb index 9c241c0..7ab0464 100644 --- a/examples/functional/lib/project_management/issue_state.rb +++ b/examples/functional/lib/project_management/issue_state.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement IssueState = Data.define(:id, :status) do diff --git a/examples/functional/lib/project_management/repository.rb b/examples/functional/lib/project_management/repository.rb index 91b3ccf..048a5a7 100644 --- a/examples/functional/lib/project_management/repository.rb +++ b/examples/functional/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository def initialize(event_store) diff --git a/examples/functional/test/issue_test.rb b/examples/functional/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/functional/test/issue_test.rb +++ b/examples/functional/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/polymorphic/Gemfile b/examples/polymorphic/Gemfile index dfa2991..b1c8640 100644 --- a/examples/polymorphic/Gemfile +++ b/examples/polymorphic/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/polymorphic/lib/project_management.rb b/examples/polymorphic/lib/project_management.rb index 2995136..5181b03 100644 --- a/examples/polymorphic/lib/project_management.rb +++ b/examples/polymorphic/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/handler" require_relative "project_management/issue" diff --git a/examples/polymorphic/lib/project_management/handler.rb b/examples/polymorphic/lib/project_management/handler.rb index 8364964..fbc5bb1 100644 --- a/examples/polymorphic/lib/project_management/handler.rb +++ b/examples/polymorphic/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/polymorphic/lib/project_management/issue.rb b/examples/polymorphic/lib/project_management/issue.rb index 82507e5..0e03a97 100644 --- a/examples/polymorphic/lib/project_management/issue.rb +++ b/examples/polymorphic/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue InvalidTransition = Class.new(StandardError) @@ -6,98 +7,127 @@ class Issue def open Open.new end + def start raise InvalidTransition end + def resolve raise InvalidTransition end + def stop raise InvalidTransition end + def reopen raise InvalidTransition end + def close raise InvalidTransition end end + class Open def open raise Issue::InvalidTransition end + def start InProgress.new end + def resolve Resolved.new end + def stop raise Issue::InvalidTransition end + def reopen raise Issue::InvalidTransition end + def close Closed.new end end + class InProgress def open raise Issue::InvalidTransition end + def start raise Issue::InvalidTransition end + def resolve Resolved.new end + def stop Open.new end + def reopen raise Issue::InvalidTransition end + def close Closed.new end end + class Resolved def open raise Issue::InvalidTransition end + def start raise Issue::InvalidTransition end + def resolve raise Issue::InvalidTransition end + def stop raise Issue::InvalidTransition end + def reopen Open.new end + def close Closed.new end end + class Closed def open raise Issue::InvalidTransition end + def start raise Issue::InvalidTransition end + def resolve raise Issue::InvalidTransition end + def stop raise Issue::InvalidTransition end + def reopen Open.new end + def close raise Issue::InvalidTransition end diff --git a/examples/polymorphic/test/issue_test.rb b/examples/polymorphic/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/polymorphic/test/issue_test.rb +++ b/examples/polymorphic/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/poro/Gemfile b/examples/poro/Gemfile index dfa2991..b1c8640 100644 --- a/examples/poro/Gemfile +++ b/examples/poro/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/poro/lib/project_management.rb b/examples/poro/lib/project_management.rb index 5d1b2a4..43c2cdc 100644 --- a/examples/poro/lib/project_management.rb +++ b/examples/poro/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/issue" require_relative "project_management/issue_projection" diff --git a/examples/poro/lib/project_management/handler.rb b/examples/poro/lib/project_management/handler.rb index ff95f9c..64dd2d3 100644 --- a/examples/poro/lib/project_management/handler.rb +++ b/examples/poro/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/poro/lib/project_management/issue.rb b/examples/poro/lib/project_management/issue.rb index 992ba8a..f425c96 100644 --- a/examples/poro/lib/project_management/issue.rb +++ b/examples/poro/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue InvalidTransition = Class.new(StandardError) diff --git a/examples/poro/lib/project_management/issue_projection.rb b/examples/poro/lib/project_management/issue_projection.rb index 9dbbd6c..e61ae3b 100644 --- a/examples/poro/lib/project_management/issue_projection.rb +++ b/examples/poro/lib/project_management/issue_projection.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class IssueProjection State = Struct.new(:status) diff --git a/examples/poro/test/issue_test.rb b/examples/poro/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/poro/test/issue_test.rb +++ b/examples/poro/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/query_based/Gemfile b/examples/query_based/Gemfile index dfa2991..b1c8640 100644 --- a/examples/query_based/Gemfile +++ b/examples/query_based/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/query_based/lib/project_management.rb b/examples/query_based/lib/project_management.rb index ee1b51e..a0699c1 100644 --- a/examples/query_based/lib/project_management.rb +++ b/examples/query_based/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/issue" require_relative "project_management/repository" diff --git a/examples/query_based/lib/project_management/handler.rb b/examples/query_based/lib/project_management/handler.rb index a9afd9e..a76a075 100644 --- a/examples/query_based/lib/project_management/handler.rb +++ b/examples/query_based/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) @@ -25,6 +26,7 @@ def call(cmd) def create(id) with_aggregate(id) do |issue| raise Error unless issue.can_create? + IssueOpened.new(data: { issue_id: id }) end end @@ -32,6 +34,7 @@ def create(id) def resolve(id) with_aggregate(id) do |issue| raise Error unless issue.can_resolve? + IssueResolved.new(data: { issue_id: id }) end end @@ -39,6 +42,7 @@ def resolve(id) def close(id) with_aggregate(id) do |issue| raise Error unless issue.can_close? + IssueClosed.new(data: { issue_id: id }) end end @@ -46,6 +50,7 @@ def close(id) def reopen(id) with_aggregate(id) do |issue| raise Error unless issue.can_reopen? + IssueReopened.new(data: { issue_id: id }) end end @@ -53,6 +58,7 @@ def reopen(id) def start(id) with_aggregate(id) do |issue| raise Error unless issue.can_start? + IssueProgressStarted.new(data: { issue_id: id }) end end @@ -60,6 +66,7 @@ def start(id) def stop(id) with_aggregate(id) do |issue| raise Error unless issue.can_stop? + IssueProgressStopped.new(data: { issue_id: id }) end end diff --git a/examples/query_based/lib/project_management/issue.rb b/examples/query_based/lib/project_management/issue.rb index e98c946..55ed692 100644 --- a/examples/query_based/lib/project_management/issue.rb +++ b/examples/query_based/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement Issue = Data.define(:status) do diff --git a/examples/query_based/lib/project_management/issue_projection.rb b/examples/query_based/lib/project_management/issue_projection.rb index 81297d8..0bf6630 100644 --- a/examples/query_based/lib/project_management/issue_projection.rb +++ b/examples/query_based/lib/project_management/issue_projection.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class IssueProjection def self.call(query, initial_issue) diff --git a/examples/query_based/lib/project_management/repository.rb b/examples/query_based/lib/project_management/repository.rb index 10c22e6..31ce071 100644 --- a/examples/query_based/lib/project_management/repository.rb +++ b/examples/query_based/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository def initialize(event_store) @@ -21,4 +22,4 @@ def store(id, events) def stream_name(id) = "Issue$#{id}" end -end \ No newline at end of file +end diff --git a/examples/query_based/test/issue_test.rb b/examples/query_based/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/query_based/test/issue_test.rb +++ b/examples/query_based/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/rails_way/Gemfile b/examples/rails_way/Gemfile index 91f8d67..2677251 100644 --- a/examples/rails_way/Gemfile +++ b/examples/rails_way/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/rails_way/lib/project_management.rb b/examples/rails_way/lib/project_management.rb index b31900b..8578c75 100644 --- a/examples/rails_way/lib/project_management.rb +++ b/examples/rails_way/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "active_record" require "aasm" diff --git a/examples/rails_way/lib/project_management/handler.rb b/examples/rails_way/lib/project_management/handler.rb index 42ff6f3..46e5b5c 100644 --- a/examples/rails_way/lib/project_management/handler.rb +++ b/examples/rails_way/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/rails_way/lib/project_management/issue.rb b/examples/rails_way/lib/project_management/issue.rb index 8120395..7a50738 100644 --- a/examples/rails_way/lib/project_management/issue.rb +++ b/examples/rails_way/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue < ActiveRecord::Base include AASM diff --git a/examples/rails_way/test/issue_test.rb b/examples/rails_way/test/issue_test.rb index a1a15f3..74f25c6 100644 --- a/examples/rails_way/test/issue_test.rb +++ b/examples/rails_way/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" diff --git a/examples/repository/Gemfile b/examples/repository/Gemfile index dfa2991..b1c8640 100644 --- a/examples/repository/Gemfile +++ b/examples/repository/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/repository/lib/project_management.rb b/examples/repository/lib/project_management.rb index dd5af64..f595637 100644 --- a/examples/repository/lib/project_management.rb +++ b/examples/repository/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/repository" require_relative "project_management/issue" diff --git a/examples/repository/lib/project_management/handler.rb b/examples/repository/lib/project_management/handler.rb index 46ef691..ee021bb 100644 --- a/examples/repository/lib/project_management/handler.rb +++ b/examples/repository/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/repository/lib/project_management/issue.rb b/examples/repository/lib/project_management/issue.rb index eadd7a7..53b84d2 100644 --- a/examples/repository/lib/project_management/issue.rb +++ b/examples/repository/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue InvalidTransition = Class.new(StandardError) diff --git a/examples/repository/lib/project_management/repository.rb b/examples/repository/lib/project_management/repository.rb index afd3380..1902373 100644 --- a/examples/repository/lib/project_management/repository.rb +++ b/examples/repository/lib/project_management/repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Repository def initialize(event_store) diff --git a/examples/repository/test/issue_test.rb b/examples/repository/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/repository/test/issue_test.rb +++ b/examples/repository/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/roles/Gemfile b/examples/roles/Gemfile index dfa2991..b1c8640 100644 --- a/examples/roles/Gemfile +++ b/examples/roles/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/roles/lib/project_management.rb b/examples/roles/lib/project_management.rb index 2995136..5181b03 100644 --- a/examples/roles/lib/project_management.rb +++ b/examples/roles/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "project_management/handler" require_relative "project_management/issue" diff --git a/examples/roles/lib/project_management/handler.rb b/examples/roles/lib/project_management/handler.rb index 3caa91e..b68a975 100644 --- a/examples/roles/lib/project_management/handler.rb +++ b/examples/roles/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) @@ -75,24 +76,24 @@ def stream_name(id) def load_issue(id) issue = @event_store - .read - .stream(stream_name(id)) - .reduce(Issue.new) do |issue, event| - case event - when IssueOpened - issue.open - when IssueProgressStarted - issue.start - when IssueProgressStopped - issue.stop - when IssueResolved - issue.resolve - when IssueReopened - issue.reopen - when IssueClosed - issue.close - end + .read + .stream(stream_name(id)) + .reduce(Issue.new) do |issue, event| + case event + when IssueOpened + issue.open + when IssueProgressStarted + issue.start + when IssueProgressStopped + issue.stop + when IssueResolved + issue.resolve + when IssueReopened + issue.reopen + when IssueClosed + issue.close end + end @event_store.append(yield(issue), stream_name: stream_name(id)) end diff --git a/examples/roles/lib/project_management/issue.rb b/examples/roles/lib/project_management/issue.rb index 92abee2..290309c 100644 --- a/examples/roles/lib/project_management/issue.rb +++ b/examples/roles/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue InvalidTransition = Class.new(StandardError) diff --git a/examples/roles/test/issue_test.rb b/examples/roles/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/roles/test/issue_test.rb +++ b/examples/roles/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/examples/yield_based/Gemfile b/examples/yield_based/Gemfile index dfa2991..b1c8640 100644 --- a/examples/yield_based/Gemfile +++ b/examples/yield_based/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source "https://rubygems.org" gem "ruby_event_store" diff --git a/examples/yield_based/lib/aggregate_repository.rb b/examples/yield_based/lib/aggregate_repository.rb index 0f52f14..57a2ffd 100644 --- a/examples/yield_based/lib/aggregate_repository.rb +++ b/examples/yield_based/lib/aggregate_repository.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + class AggregateRepository def initialize(event_store) @event_store = event_store diff --git a/examples/yield_based/lib/aggregate_root.rb b/examples/yield_based/lib/aggregate_root.rb index a92f378..5cf86f4 100644 --- a/examples/yield_based/lib/aggregate_root.rb +++ b/examples/yield_based/lib/aggregate_root.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + module AggregateRoot module ClassMethods def on(*event_klasses, &block) event_klasses.each do |event_klass| name = event_klass.name || - raise(ArgumentError, "Anonymous class is missing name") + raise(ArgumentError, "Anonymous class is missing name") handler_name = "on_#{name}" define_method(handler_name, &block) @on_methods ||= {} diff --git a/examples/yield_based/lib/project_management.rb b/examples/yield_based/lib/project_management.rb index cc170b2..ffd3d10 100644 --- a/examples/yield_based/lib/project_management.rb +++ b/examples/yield_based/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "../../../shared/lib/project_management" require_relative "aggregate_root" require_relative "aggregate_repository" diff --git a/examples/yield_based/lib/project_management/handler.rb b/examples/yield_based/lib/project_management/handler.rb index d63a6b7..6a2588a 100644 --- a/examples/yield_based/lib/project_management/handler.rb +++ b/examples/yield_based/lib/project_management/handler.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Handler def initialize(event_store) diff --git a/examples/yield_based/lib/project_management/issue.rb b/examples/yield_based/lib/project_management/issue.rb index 86bf593..58cfb46 100644 --- a/examples/yield_based/lib/project_management/issue.rb +++ b/examples/yield_based/lib/project_management/issue.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement class Issue include AggregateRoot diff --git a/examples/yield_based/test/issue_test.rb b/examples/yield_based/test/issue_test.rb index aeb4c33..c14358d 100644 --- a/examples/yield_based/test/issue_test.rb +++ b/examples/yield_based/test/issue_test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "minitest/autorun" require "minitest/mock" require "mutant/minitest/coverage" @@ -9,9 +10,9 @@ module ProjectManagement class IssueTest < Minitest::Test include Test.with( - handler: ->(event_store) { Handler.new(event_store) }, - event_store: -> { RubyEventStore::Client.new } - ) + handler: ->(event_store) { Handler.new(event_store) }, + event_store: -> { RubyEventStore::Client.new } + ) cover "ProjectManagement::Issue*" end diff --git a/shared/lib/project_management.rb b/shared/lib/project_management.rb index 56a8af0..54307a7 100644 --- a/shared/lib/project_management.rb +++ b/shared/lib/project_management.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require_relative "project_management/commands" require_relative "project_management/events" require_relative "project_management/errors" diff --git a/shared/lib/project_management/commands.rb b/shared/lib/project_management/commands.rb index 4ca8399..8100fc9 100644 --- a/shared/lib/project_management/commands.rb +++ b/shared/lib/project_management/commands.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement Command = Data.define(:id) diff --git a/shared/lib/project_management/errors.rb b/shared/lib/project_management/errors.rb index 49dc042..39dfff0 100644 --- a/shared/lib/project_management/errors.rb +++ b/shared/lib/project_management/errors.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement Error = Class.new(StandardError) end diff --git a/shared/lib/project_management/events.rb b/shared/lib/project_management/events.rb index 8baa4b3..1f39fd7 100644 --- a/shared/lib/project_management/events.rb +++ b/shared/lib/project_management/events.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true + module ProjectManagement Event = Data.define(:event_id, :data, :metadata) do def initialize(event_id: SecureRandom.uuid, data: {}, metadata: {}) = super(event_id: event_id, data: data, metadata: metadata) + def event_type = self.class.name end diff --git a/shared/lib/project_management/test.rb b/shared/lib/project_management/test.rb index 69c8b34..6e95cca 100644 --- a/shared/lib/project_management/test.rb +++ b/shared/lib/project_management/test.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module ProjectManagement module Test def self.with(handler:, event_store:)