Sha256: 997aed31f1e434751d57a618ddce7f41e73ebc2ff733b2050c52bba1e07dd254

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'active_support/concern'

module RailsWorkflow
  module Status
    extend ActiveSupport::Concern

    NOT_STARTED = 0
    IN_PROGRESS = 1
    DONE = 2
    WAITING = 3
    ERROR = 4
    CANCELED = 5
    SKIPPED = 6
    ROLLBACK = 7

    module ClassMethods
      def all_statuses
        (NOT_STARTED..ROLLBACK).to_a
      end

      def get_status_code status
        case status
          when "in_progress"
            IN_PROGRESS
          when "done"
            DONE
          when "not_started"
            NOT_STARTED
          when "waiting"
            WAITING
          when "error"
            ERROR
        end
      end

    end

    included do

      def incomplete_statuses
        [NOT_STARTED, IN_PROGRESS, WAITING]
      end

      def completed_statuses
        [DONE, CANCELED, SKIPPED, ROLLBACK]
      end

      def get_status_values
        [
            [NOT_STARTED, 'Not Started'],
            [IN_PROGRESS, 'In Progress'],
            [DONE, 'Done'],
            [WAITING, 'Waiting'],
            [ERROR, 'Error'],
            [CANCELED, 'Canceled'],
            [SKIPPED, 'Skipped'],
            [ROLLBACK, 'Rollback']
        ]
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_workflow-0.3.7 app/concerns/rails_workflow/status.rb
rails_workflow-0.3.6 app/concerns/rails_workflow/status.rb