-
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.
- Loading branch information
1 parent
951989c
commit 8983aed
Showing
3 changed files
with
42 additions
and
25 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module ProjectManagement | ||
class Repository | ||
def initialize(event_store) | ||
@event_store = event_store | ||
end | ||
|
||
def load(id, initial_issue) | ||
@event_store | ||
.read | ||
.stream(stream_name(id)) | ||
.reduce(initial_issue) 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 | ||
end | ||
|
||
def store(id, events) | ||
@event_store.append(events, stream_name: stream_name(id)) | ||
end | ||
|
||
private | ||
|
||
def stream_name(id) = "Issue$#{id}" | ||
end | ||
end |