Skip to content

Commit

Permalink
adjust duck_typing implementation to satisfy mutant
Browse files Browse the repository at this point in the history
Co-authored-by: Szymon Fiedler <[email protected]>
Co-authored-by: Paweł Pacana <[email protected]>
  • Loading branch information
3 people committed Oct 20, 2023
1 parent 2c3db29 commit c160537
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions duck_typing/project_management/command_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,56 @@ def initialize(event_store)

def create(cmd)
load_issue(cmd.id) do |issue|
raise_invalid unless issue.respond_to?(:open)
issue.open
IssueOpened.new(data: { issue_id: cmd.id })
end
rescue NoMethodError
raise_invalid
end

def close(cmd)
load_issue(cmd.id) do |issue|
raise_invalid unless issue.respond_to?(:close)
issue.close
IssueClosed.new(data: { issue_id: cmd.id })
end
rescue NoMethodError
raise_invalid
end

def start(cmd)
load_issue(cmd.id) do |issue|
raise_invalid unless issue.respond_to?(:start)
issue.start
IssueProgressStarted.new(data: { issue_id: cmd.id })
end
rescue NoMethodError
raise_invalid
end

def stop(cmd)
load_issue(cmd.id) do |issue|
raise_invalid unless issue.respond_to?(:stop)
issue.stop
IssueProgressStopped.new(data: { issue_id: cmd.id })
end
rescue NoMethodError
raise_invalid
end

def reopen(cmd)
load_issue(cmd.id) do |issue|
raise_invalid unless issue.respond_to?(:reopen)
issue.reopen
IssueReopened.new(data: { issue_id: cmd.id })
end
rescue NoMethodError
raise_invalid
end

def resolve(cmd)
load_issue(cmd.id) do |issue|
raise_invalid unless issue.respond_to?(:resolve)
issue.resolve
IssueResolved.new(data: { issue_id: cmd.id })
end
rescue NoMethodError
raise_invalid
end

private
Expand All @@ -74,22 +80,22 @@ def load_issue(id)
.read
.stream(stream_name(id))
.each do |event|
case event
when IssueOpened
issue = issue.open
when IssueProgressStarted
issue = issue.start
when IssueProgressStopped
issue = issue.stop
when IssueResolved
issue = issue.resolve
when IssueReopened
issue = issue.reopen
when IssueClosed
issue = issue.close
end
version += 1
case event
when IssueOpened
issue = issue.open
when IssueProgressStarted
issue = issue.start
when IssueProgressStopped
issue = issue.stop
when IssueResolved
issue = issue.resolve
when IssueReopened
issue = issue.reopen
when IssueClosed
issue = issue.close
end
version += 1
end
events = yield issue
publish(events, id, version)
end
Expand Down

0 comments on commit c160537

Please sign in to comment.