Sha256: 5c85d92e9efdff19222f26f4b60324885de12514487467c98c0ae5c3e68e04a4
Contents?: true
Size: 841 Bytes
Versions: 5
Compression:
Stored size: 841 Bytes
Contents
require 'active_support/concern' module IntegrationPal module Statusable extend ActiveSupport::Concern PENDING_STATUS = 'pending'.freeze COMPLETED_STATUS = 'completed'.freeze IN_PROGRESS_STATUS = 'in_progress'.freeze FAILED_STATUS = 'failed'.freeze STATUSES = [PENDING_STATUS, COMPLETED_STATUS, IN_PROGRESS_STATUS, FAILED_STATUS].freeze included do validates :status, presence: true, inclusion: { in: STATUSES } before_validation :set_status def set_status self.status ||= PENDING_STATUS end def fail(exception) self.update_attributes(status: FAILED_STATUS, error: exception.message, backtrace: exception.backtrace) end def complete self.update_attributes(status: COMPLETED_STATUS, finished_at: Time.zone.now) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems