Class: GitlabUploader
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(model, mounted_as = nil, **uploader_context) ⇒ GitlabUploader
Returns a new instance of GitlabUploader.
36
37
38
|
# File 'app/uploaders/gitlab_uploader.rb', line 36
def initialize(model, mounted_as = nil, **uploader_context)
super(model, mounted_as)
end
|
Class Method Details
.absolute_path(upload_record) ⇒ Object
27
28
29
|
# File 'app/uploaders/gitlab_uploader.rb', line 27
def absolute_path(upload_record)
File.join(root, upload_record.path)
end
|
.base_dir ⇒ Object
represent the directory namespacing at the class level
19
20
21
|
# File 'app/uploaders/gitlab_uploader.rb', line 19
def base_dir
options.fetch('base_dir', '')
end
|
.file_storage? ⇒ Boolean
23
24
25
|
# File 'app/uploaders/gitlab_uploader.rb', line 23
def file_storage?
storage == CarrierWave::Storage::File
end
|
.root ⇒ Object
14
15
16
|
# File 'app/uploaders/gitlab_uploader.rb', line 14
def root
options.storage_path
end
|
.storage_options(options) ⇒ Object
10
11
12
|
# File 'app/uploaders/gitlab_uploader.rb', line 10
def storage_options(options)
self.options = options
end
|
Instance Method Details
#cache_dir ⇒ Object
56
57
58
|
# File 'app/uploaders/gitlab_uploader.rb', line 56
def cache_dir
File.join(root, base_dir, 'tmp/cache')
end
|
#cached_size ⇒ Object
82
83
84
|
# File 'app/uploaders/gitlab_uploader.rb', line 82
def cached_size
size
end
|
#exists? ⇒ Boolean
52
53
54
|
# File 'app/uploaders/gitlab_uploader.rb', line 52
def exists?
file.present?
end
|
#file_cache_storage? ⇒ Boolean
40
41
42
|
# File 'app/uploaders/gitlab_uploader.rb', line 40
def file_cache_storage?
cache_storage.is_a?(CarrierWave::Storage::File)
end
|
#filename ⇒ Object
64
65
66
|
# File 'app/uploaders/gitlab_uploader.rb', line 64
def filename
super || file&.filename
end
|
#local_url ⇒ Object
78
79
80
|
# File 'app/uploaders/gitlab_uploader.rb', line 78
def local_url
File.join('/', self.class.base_dir, dynamic_segment, filename)
end
|
#model_valid? ⇒ Boolean
74
75
76
|
# File 'app/uploaders/gitlab_uploader.rb', line 74
def model_valid?
!!model
end
|
#move_to_cache ⇒ Object
44
45
46
|
# File 'app/uploaders/gitlab_uploader.rb', line 44
def move_to_cache
file_storage?
end
|
#move_to_store ⇒ Object
48
49
50
|
# File 'app/uploaders/gitlab_uploader.rb', line 48
def move_to_store
file_storage?
end
|
#open ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/uploaders/gitlab_uploader.rb', line 86
def open
stream =
if file_storage?
File.open(path, "rb") if path
else
::Gitlab::HttpIO.new(url, cached_size) if url
end
return unless stream
return stream unless block_given?
begin
yield(stream)
ensure
stream.close
end
end
|
#relative_path ⇒ Object
68
69
70
71
72
|
# File 'app/uploaders/gitlab_uploader.rb', line 68
def relative_path
return path if pathname.relative?
pathname.relative_path_from(Pathname.new(root))
end
|
#replace_file_without_saving!(file) ⇒ Object
Used to replace an existing upload with another file
without modifying stored metadata Use this method only to repair/replace an existing upload, or to upload to a Geo secondary node
109
110
111
112
113
|
# File 'app/uploaders/gitlab_uploader.rb', line 109
def replace_file_without_saving!(file)
raise ArgumentError, 'should be a CarrierWave::SanitizedFile' unless file.is_a? CarrierWave::SanitizedFile
storage.store!(file)
end
|
#work_dir ⇒ Object
60
61
62
|
# File 'app/uploaders/gitlab_uploader.rb', line 60
def work_dir
File.join(root, base_dir, 'tmp/work')
end
|