artifact_uploader.rb 985 字节
Newer Older
K
Kamil Trzcinski 已提交
1 2 3 4 5 6 7 8 9 10 11
# encoding: utf-8
class ArtifactUploader < CarrierWave::Uploader::Base
  storage :file

  attr_accessor :build, :field

  def self.artifacts_path
    File.expand_path('shared/artifacts/', Rails.root)
  end

  def self.artifacts_upload_path
12
    File.expand_path('shared/artifacts/tmp/uploads/', Rails.root)
K
Kamil Trzcinski 已提交
13 14 15
  end

  def self.artifacts_cache_path
16
    File.expand_path('shared/artifacts/tmp/cache/', Rails.root)
K
Kamil Trzcinski 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  end

  def initialize(build, field)
    @build, @field = build, field
  end

  def artifacts_path
    File.join(build.created_at.utc.strftime('%Y_%m'), build.project.id.to_s, build.id.to_s)
  end

  def store_dir
    File.join(ArtifactUploader.artifacts_path, artifacts_path)
  end

  def cache_dir
    File.join(ArtifactUploader.artifacts_cache_path, artifacts_path)
  end

  def file_storage?
    self.class.storage == CarrierWave::Storage::File
  end

  def exists?
    file.try(:exists?)
  end

  def move_to_cache
    true
  end

  def move_to_store
    true
  end
end