Skip to content

Commit

Permalink
More formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious committed Nov 20, 2024
1 parent e09dd6e commit 2117af0
Show file tree
Hide file tree
Showing 94 changed files with 211 additions and 63 deletions.
1 change: 1 addition & 0 deletions examples/actor_like/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_event_store"
Expand Down
1 change: 1 addition & 0 deletions examples/actor_like/lib/aggregate_repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

class AggregateRepository
def initialize(event_store)
@event_store = event_store
Expand Down
3 changes: 2 additions & 1 deletion examples/actor_like/lib/aggregate_root.rb
Original file line number Diff line number Diff line change
@@ -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 ||= {}
Expand Down
3 changes: 2 additions & 1 deletion examples/actor_like/lib/aggregate_state.rb
Original file line number Diff line number Diff line change
@@ -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 ||= {}
Expand Down
1 change: 1 addition & 0 deletions examples/actor_like/lib/project_management.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative "../../../shared/lib/project_management"
require_relative "aggregate_state"
require_relative "aggregate_root"
Expand Down
1 change: 1 addition & 0 deletions examples/actor_like/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Handler
def initialize(event_store)
Expand Down
1 change: 1 addition & 0 deletions examples/actor_like/lib/project_management/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Issue
include AggregateRoot
Expand Down
1 change: 1 addition & 0 deletions examples/actor_like/lib/project_management/issue_state.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class IssueState < Struct.new(:id, :status)
include AggregateState
Expand Down
7 changes: 4 additions & 3 deletions examples/actor_like/test/issue_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "minitest/autorun"
require "minitest/mock"
require "mutant/minitest/coverage"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/aggregate_root/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_event_store"
Expand Down
1 change: 1 addition & 0 deletions examples/aggregate_root/lib/project_management.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "aggregate_root"

require_relative "../../../shared/lib/project_management"
Expand Down
1 change: 1 addition & 0 deletions examples/aggregate_root/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Handler
def initialize(event_store)
Expand Down
7 changes: 7 additions & 0 deletions examples/aggregate_root/lib/project_management/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Issue
include AggregateRoot
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
Repository = AggregateRoot::Repository
end
7 changes: 4 additions & 3 deletions examples/aggregate_root/test/issue_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "minitest/autorun"
require "minitest/mock"
require "mutant/minitest/coverage"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/decider/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_event_store"
Expand Down
1 change: 1 addition & 0 deletions examples/decider/lib/project_management.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative "../../../shared/lib/project_management"
require_relative "project_management/handler"
require_relative "project_management/issue"
Expand Down
1 change: 1 addition & 0 deletions examples/decider/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Handler
def initialize(event_store)
Expand Down
1 change: 1 addition & 0 deletions examples/decider/lib/project_management/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
module Issue
InvalidTransition = Class.new(StandardError)
Expand Down
1 change: 1 addition & 0 deletions examples/decider/lib/project_management/repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Repository
def initialize(event_store)
Expand Down
7 changes: 4 additions & 3 deletions examples/decider/test/issue_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "minitest/autorun"
require "minitest/mock"
require "mutant/minitest/coverage"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/document_way/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_event_store"
Expand Down
1 change: 1 addition & 0 deletions examples/document_way/lib/project_management.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "active_record"

require_relative "../../../shared/lib/project_management"
Expand Down
1 change: 1 addition & 0 deletions examples/document_way/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Handler
def initialize(event_store)
Expand Down
7 changes: 7 additions & 0 deletions examples/document_way/lib/project_management/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Issue
InvalidTransition = Class.new(StandardError)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/document_way/lib/project_management/repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Repository
class Record < ActiveRecord::Base
Expand Down
7 changes: 4 additions & 3 deletions examples/document_way/test/issue_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "minitest/autorun"
require "minitest/mock"
require "mutant/minitest/coverage"
Expand All @@ -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*"

Expand Down
1 change: 1 addition & 0 deletions examples/duck_typing/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_event_store"
Expand Down
1 change: 1 addition & 0 deletions examples/duck_typing/lib/project_management.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "tty-prompt"

require_relative "../../../shared/lib/project_management"
Expand Down
1 change: 1 addition & 0 deletions examples/duck_typing/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Handler
def initialize(event_store)
Expand Down
1 change: 1 addition & 0 deletions examples/duck_typing/lib/project_management/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Issue
def open = Open.new
Expand Down
1 change: 1 addition & 0 deletions examples/duck_typing/lib/project_management/repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Repository
def initialize(event_store)
Expand Down
1 change: 1 addition & 0 deletions examples/duck_typing/lib/project_management/ui.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class UI
def initialize
Expand Down
7 changes: 4 additions & 3 deletions examples/duck_typing/test/issue_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "minitest/autorun"
require "minitest/mock"
require "mutant/minitest/coverage"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/extracted_state/Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby_event_store"
Expand Down
1 change: 1 addition & 0 deletions examples/extracted_state/lib/project_management.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative "../../../shared/lib/project_management"
require_relative "project_management/handler"
require_relative "project_management/issue"
Expand Down
1 change: 1 addition & 0 deletions examples/extracted_state/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

module ProjectManagement
class Handler
def initialize(event_store)
Expand Down
Loading

0 comments on commit 2117af0

Please sign in to comment.