-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Focus more on state in extracted_state sample
- Loading branch information
1 parent
e416232
commit 2fd896d
Showing
3 changed files
with
55 additions
and
119 deletions.
There are no files selected for viewing
61 changes: 21 additions & 40 deletions
61
examples/extracted_state/lib/project_management/command_handler.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 20 additions & 22 deletions
42
examples/extracted_state/lib/project_management/issue_state.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
module ProjectManagement | ||
class IssueState < Struct.new(:id, :status) | ||
def initial? = status.nil? | ||
def open? = status == :open | ||
def closed? = status == :closed | ||
def in_progress? = status == :in_progress | ||
def reopened? = status == :reopened | ||
def resolved? = status == :resolved | ||
IssueState = | ||
Data.define(:id, :status) do | ||
def self.initial(id) | ||
new(id: id, status: nil) | ||
end | ||
|
||
def apply(event) | ||
case event | ||
when IssueOpened | ||
self.status = :open | ||
when IssueResolved | ||
self.status = :resolved | ||
when IssueClosed | ||
self.status = :closed | ||
when IssueReopened | ||
self.status = :reopened | ||
when IssueProgressStarted | ||
self.status = :in_progress | ||
when IssueProgressStopped | ||
self.status = :open | ||
def apply(event) | ||
case event | ||
when IssueOpened | ||
with(status: :open) | ||
when IssueResolved | ||
with(status: :resolved) | ||
when IssueClosed | ||
with(status: :closed) | ||
when IssueReopened | ||
with(status: :reopened) | ||
when IssueProgressStarted | ||
with(status: :in_progress) | ||
when IssueProgressStopped | ||
with(status: :open) | ||
end | ||
end | ||
end | ||
end | ||
end |