aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/import.rb
blob: 3cbdb964fc1256c7dee88ecc25a2debf0e4c7d5c (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
29
class Import < ActiveRecord::Base
  mount_uploader :file, ImportUploader
  belongs_to :workbench
  belongs_to :referential

  belongs_to :parent, polymorphic: true

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

  validates :file, presence: true
  validates_presence_of :referential, :workbench

  before_create :initialize_fields

  def notify_parent
    parent.child_change(self)
  end

  def child_change(child)
  end

  private

  def initialize_fields
    self.token_download = SecureRandom.urlsafe_base64
    self.status = Import.status.new
  end
end