aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/concerns/iev_interfaces/resource.rb
blob: 254f88a3377083f11daf992b1fadfce10c2a713d (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
module IevInterfaces::Resource
  extend ActiveSupport::Concern

  included do
    extend Enumerize
    enumerize :status, in: %i(OK ERROR WARNING IGNORED), scope: true
    validates_presence_of :name, :resource_type
  end

  def update_status_from_importer importer_status
    self.update status: status_from_importer(importer_status)
  end

  def status_from_importer importer_status
    return nil unless importer_status.present?
    {
      new: nil,
      pending: nil,
      successful: :OK,
      warning: :WARNING,
      failed: :ERROR,
      running: nil,
      aborted: :ERROR,
      canceled: :ERROR
    }[importer_status.to_sym]
  end
end