Sha256: 7f1227b82d77d455e1a391182eee9bcc3772706604211cdf520dd1c8becff577
Contents?: true
Size: 943 Bytes
Versions: 10
Compression:
Stored size: 943 Bytes
Contents
module RailsExecution module Services class Approvement def initialize(task, reviewer: nil) @task = task || (raise 'task is blank') @reviewer = reviewer || (raise 'reviewer is blank') end def approve task.update(status: :approved) review.update(status: :approved) add_activity('approved') end def reject review.update(status: :rejected) task.update(status: :rejected) if make_task_to_rejected? add_activity('rejected') end private attr_reader :task attr_reader :reviewer def review @review ||= task.task_reviews.find_or_initialize_by(owner: reviewer) end def add_activity(status) task.activities.create(owner: reviewer, message: "#{status.titleize} the task") end def make_task_to_rejected? task.task_reviews.is_approved.empty? end end end end
Version data entries
10 entries across 10 versions & 1 rubygems