artifact_migratable.rb 1.02 KB
Newer Older
1 2 3 4 5
# Adapter class to unify the interface between mounted uploaders and the
# Ci::Artifact model
# Meant to be prepended so the interface can stay the same
module ArtifactMigratable
  def artifacts_file
6
    job_artifacts_archive&.file || legacy_artifacts_file
7 8
  end

9
  def artifacts_metadata
10
    job_artifacts_metadata&.file || legacy_artifacts_metadata
11 12 13 14 15 16 17 18 19 20
  end

  def artifacts?
    !artifacts_expired? && artifacts_file.exists?
  end

  def artifacts_metadata?
    artifacts? && artifacts_metadata.exists?
  end

21
  def artifacts_file_changed?
22
    job_artifacts_archive&.file_changed? || attribute_changed?(:artifacts_file)
23 24
  end

25
  def remove_artifacts_file!
26 27
    if job_artifacts_archive
      job_artifacts_archive.destroy
28
    else
29
      remove_legacy_artifacts_file!
30
    end
31 32
  end

33
  def remove_artifacts_metadata!
34 35
    if job_artifacts_metadata
      job_artifacts_metadata.destroy
36
    else
37
      remove_legacy_artifacts_metadata!
38
    end
39 40
  end

41
  def artifacts_size
42
    read_attribute(:artifacts_size).to_i + job_artifacts.sum(:size).to_i
43 44
  end
end