gitlab-org--gitlab-foss/app/uploaders/gitlab_uploader.rb

49 lines
1.1 KiB
Ruby
Raw Normal View History

2016-08-18 14:31:44 +00:00
class GitlabUploader < CarrierWave::Uploader::Base
def self.absolute_path(upload_record)
File.join(CarrierWave.root, upload_record.path)
end
def self.base_dir
'uploads'
end
delegate :base_dir, to: :class
def local_file?
local_storage? && file&.is_a?(CarrierWave::SanitizedFile)
end
def local_storage?
storage.is_a?(CarrierWave::Storage::File)
end
def local_cache_storage?
cache_storage.is_a?(CarrierWave::Storage::File)
end
2016-08-18 14:31:44 +00:00
# Reduce disk IO
def move_to_cache
true
end
# Reduce disk IO
def move_to_store
true
end
# Designed to be overridden by child uploaders that have a dynamic path
# segment -- that is, a path that changes based on mutable attributes of its
# associated model
#
# For example, `FileUploader` builds the storage path based on the associated
# project model's `path_with_namespace` value, which can change when the
# project or its containing namespace is moved or renamed.
def relative_path
self.file.path.sub("#{root}/", '')
end
def exists?
file.try(:exists?)
end
2016-08-18 14:31:44 +00:00
end