aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/import_resource.rb
blob: 3ddd325fd98a02f229b2870c6dd0938110d90e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class ImportResource < ActiveRecord::Base
  include AASM
  belongs_to :import

  extend Enumerize
  enumerize :status, in: %i(new pending successful failed)

  validates_presence_of :name, :type, :reference

  aasm column: :status do
    state :new, :initial => true
    state :pending
    state :successful
    state :failed

    event :run do
      transitions :from => [:new, :failed], :to => :pending
    end

    event :successful do
      transitions :from => [:pending, :failed], :to => :successful
    end

    event :failed do
      transitions :from => :pending, :to => :failed
    end
  end
end