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

Version Path
rails_execution-0.1.12 lib/rails_execution/services/approvement.rb
rails_execution-0.1.11 lib/rails_execution/services/approvement.rb
rails_execution-0.1.10 lib/rails_execution/services/approvement.rb
rails_execution-0.1.9 lib/rails_execution/services/approvement.rb
rails_execution-0.1.8 lib/rails_execution/services/approvement.rb
rails_execution-0.1.7 lib/rails_execution/services/approvement.rb
rails_execution-0.1.5 lib/rails_execution/services/approvement.rb
rails_execution-0.1.4 lib/rails_execution/services/approvement.rb
rails_execution-0.1.2 lib/rails_execution/services/approvement.rb
rails_execution-0.1.1 lib/rails_execution/services/approvement.rb