From b1b98da67d12b9f33f75253711f565e696221bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Fri, 20 Oct 2023 22:25:46 +0200 Subject: [PATCH] Seems redundant --- aggregate_root/project_management/issue.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/aggregate_root/project_management/issue.rb b/aggregate_root/project_management/issue.rb index bbb7e9d..274951d 100644 --- a/aggregate_root/project_management/issue.rb +++ b/aggregate_root/project_management/issue.rb @@ -11,44 +11,38 @@ def initialize(id) end def open - fail unless initial? + fail if @status apply(IssueOpened.new(data: { issue_id: @id })) end def resolve - fail unless open? || reopened? || in_progress? + fail unless %i[open in_progress reopened].include? @status apply(IssueResolved.new(data: { issue_id: @id })) end def close - fail unless open? || in_progress? || reopened? || resolved? + fail unless %i[open in_progress resolved reopened].include? @status apply(IssueClosed.new(data: { issue_id: @id })) end def reopen - fail unless closed? || resolved? + fail unless %i[resolved closed].include? @status apply(IssueReopened.new(data: { issue_id: @id })) end def start - fail unless open? || reopened? + fail unless %i[open reopened].include? @status apply(IssueProgressStarted.new(data: { issue_id: @id })) end def stop - fail unless in_progress? + fail unless %i[in_progress].include? @status apply(IssueProgressStopped.new(data: { issue_id: @id })) end private def fail = raise InvalidTransition - 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 on(IssueOpened) { |event| @status = :open } on(IssueResolved) { |event| @status = :resolved }