aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/import/base.rb
blob: e2ae129beb0965b98435f3deff6d838c7a66fbd4 (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
30
31
32
33
34
35
36
37
38
39
40
class Import::Base < ActiveRecord::Base
  self.table_name = "imports"

  def self.messages_class_name
    "Import::Message"
  end

  def self.resources_class_name
    "Import::Resource"
  end

  include IevInterfaces::Task

  def self.model_name
    ActiveModel::Name.new Import::Base, Import::Base, "Import::Base"
  end

  def child_change
    return if self.class.finished_statuses.include?(status)

    super
    update_referentials
  end

  def update_referentials
    return unless self.class.finished_statuses.include?(status)

    children.each do |import|
      import.referential.update(ready: true) if import.referential
    end
  end

  private

  def initialize_fields
    super
    self.token_download = SecureRandom.urlsafe_base64
  end

end