carrierwave 0.11.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of carrierwave might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/README.md +294 -124
- data/lib/carrierwave.rb +34 -8
- data/lib/carrierwave/compatibility/paperclip.rb +0 -2
- data/lib/carrierwave/downloader/base.rb +50 -0
- data/lib/carrierwave/downloader/remote_file.rb +44 -0
- data/lib/carrierwave/error.rb +1 -0
- data/lib/carrierwave/locale/en.yml +7 -4
- data/lib/carrierwave/mount.rb +229 -180
- data/lib/carrierwave/mounter.rb +188 -0
- data/lib/carrierwave/orm/activerecord.rb +59 -24
- data/lib/carrierwave/processing.rb +0 -1
- data/lib/carrierwave/processing/mini_magick.rb +137 -83
- data/lib/carrierwave/processing/rmagick.rb +54 -5
- data/lib/carrierwave/sanitized_file.rb +50 -30
- data/lib/carrierwave/storage.rb +1 -9
- data/lib/carrierwave/storage/abstract.rb +15 -2
- data/lib/carrierwave/storage/file.rb +69 -2
- data/lib/carrierwave/storage/fog.rb +177 -37
- data/lib/carrierwave/test/matchers.rb +77 -12
- data/lib/carrierwave/uploader.rb +2 -2
- data/lib/carrierwave/uploader/cache.rb +60 -38
- data/lib/carrierwave/uploader/callbacks.rb +0 -2
- data/lib/carrierwave/uploader/configuration.rb +71 -13
- data/lib/carrierwave/uploader/content_type_whitelist.rb +1 -1
- data/lib/carrierwave/uploader/default_url.rb +3 -5
- data/lib/carrierwave/uploader/download.rb +4 -74
- data/lib/carrierwave/uploader/extension_blacklist.rb +14 -10
- data/lib/carrierwave/uploader/extension_whitelist.rb +13 -10
- data/lib/carrierwave/uploader/file_size.rb +43 -0
- data/lib/carrierwave/uploader/mountable.rb +13 -8
- data/lib/carrierwave/uploader/processing.rb +10 -10
- data/lib/carrierwave/uploader/proxy.rb +6 -8
- data/lib/carrierwave/uploader/remove.rb +0 -2
- data/lib/carrierwave/uploader/serialization.rb +2 -4
- data/lib/carrierwave/uploader/store.rb +17 -24
- data/lib/carrierwave/uploader/url.rb +3 -5
- data/lib/carrierwave/uploader/versions.rb +123 -93
- data/lib/carrierwave/utilities.rb +0 -3
- data/lib/carrierwave/utilities/uri.rb +5 -6
- data/lib/carrierwave/validations/active_model.rb +3 -5
- data/lib/carrierwave/version.rb +1 -1
- data/lib/generators/templates/uploader.rb +4 -8
- metadata +80 -65
- data/lib/carrierwave/locale/cs.yml +0 -11
- data/lib/carrierwave/locale/de.yml +0 -11
- data/lib/carrierwave/locale/el.yml +0 -11
- data/lib/carrierwave/locale/es.yml +0 -11
- data/lib/carrierwave/locale/fr.yml +0 -11
- data/lib/carrierwave/locale/ja.yml +0 -11
- data/lib/carrierwave/locale/nb.yml +0 -11
- data/lib/carrierwave/locale/nl.yml +0 -11
- data/lib/carrierwave/locale/pl.yml +0 -11
- data/lib/carrierwave/locale/pt-BR.yml +0 -11
- data/lib/carrierwave/locale/pt-PT.yml +0 -11
- data/lib/carrierwave/locale/ru.yml +0 -11
- data/lib/carrierwave/locale/sk.yml +0 -11
- data/lib/carrierwave/locale/tr.yml +0 -11
- data/lib/carrierwave/processing/mime_types.rb +0 -74
- data/lib/carrierwave/utilities/deprecation.rb +0 -18
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
module CarrierWave
|
4
2
|
module Test
|
5
3
|
|
@@ -23,13 +21,16 @@ module CarrierWave
|
|
23
21
|
"expected #{@actual.inspect} to be identical to #{@expected.inspect}"
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
24
|
+
def failure_message_when_negated
|
27
25
|
"expected #{@actual.inspect} to not be identical to #{@expected.inspect}"
|
28
26
|
end
|
29
27
|
|
30
28
|
def description
|
31
29
|
"be identical to #{@expected.inspect}"
|
32
30
|
end
|
31
|
+
|
32
|
+
# RSpec 2 compatibility:
|
33
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
33
34
|
end
|
34
35
|
|
35
36
|
def be_identical_to(expected)
|
@@ -51,13 +52,16 @@ module CarrierWave
|
|
51
52
|
"expected #{@actual.current_path.inspect} to have permissions #{@expected.to_s(8)}, but they were #{(File.stat(@actual.path).mode & 0777).to_s(8)}"
|
52
53
|
end
|
53
54
|
|
54
|
-
def
|
55
|
+
def failure_message_when_negated
|
55
56
|
"expected #{@actual.current_path.inspect} not to have permissions #{@expected.to_s(8)}, but it did"
|
56
57
|
end
|
57
58
|
|
58
59
|
def description
|
59
60
|
"have permissions #{@expected.to_s(8)}"
|
60
61
|
end
|
62
|
+
|
63
|
+
# RSpec 2 compatibility:
|
64
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
61
65
|
end
|
62
66
|
|
63
67
|
def have_permissions(expected)
|
@@ -79,13 +83,16 @@ module CarrierWave
|
|
79
83
|
"expected #{File.dirname @actual.current_path.inspect} to have permissions #{@expected.to_s(8)}, but they were #{(File.stat(@actual.path).mode & 0777).to_s(8)}"
|
80
84
|
end
|
81
85
|
|
82
|
-
def
|
86
|
+
def failure_message_when_negated
|
83
87
|
"expected #{File.dirname @actual.current_path.inspect} not to have permissions #{@expected.to_s(8)}, but it did"
|
84
88
|
end
|
85
89
|
|
86
90
|
def description
|
87
91
|
"have permissions #{@expected.to_s(8)}"
|
88
92
|
end
|
93
|
+
|
94
|
+
# RSpec 2 compatibility:
|
95
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
89
96
|
end
|
90
97
|
|
91
98
|
def have_directory_permissions(expected)
|
@@ -110,13 +117,16 @@ module CarrierWave
|
|
110
117
|
"expected #{@actual.current_path.inspect} to be no larger than #{@width} by #{@height}, but it was #{@actual_width} by #{@actual_height}."
|
111
118
|
end
|
112
119
|
|
113
|
-
def
|
120
|
+
def failure_message_when_negated
|
114
121
|
"expected #{@actual.current_path.inspect} to be larger than #{@width} by #{@height}, but it wasn't."
|
115
122
|
end
|
116
123
|
|
117
124
|
def description
|
118
125
|
"be no larger than #{@width} by #{@height}"
|
119
126
|
end
|
127
|
+
|
128
|
+
# RSpec 2 compatibility:
|
129
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
120
130
|
end
|
121
131
|
|
122
132
|
def be_no_larger_than(width, height)
|
@@ -141,13 +151,16 @@ module CarrierWave
|
|
141
151
|
"expected #{@actual.current_path.inspect} to have an exact size of #{@width} by #{@height}, but it was #{@actual_width} by #{@actual_height}."
|
142
152
|
end
|
143
153
|
|
144
|
-
def
|
154
|
+
def failure_message_when_negated
|
145
155
|
"expected #{@actual.current_path.inspect} not to have an exact size of #{@width} by #{@height}, but it did."
|
146
156
|
end
|
147
157
|
|
148
158
|
def description
|
149
159
|
"have an exact size of #{@width} by #{@height}"
|
150
160
|
end
|
161
|
+
|
162
|
+
# RSpec 2 compatibility:
|
163
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
151
164
|
end
|
152
165
|
|
153
166
|
def have_dimensions(width, height)
|
@@ -171,13 +184,16 @@ module CarrierWave
|
|
171
184
|
"expected #{@actual.current_path.inspect} to have an exact size of #{@height}, but it was #{@actual_height}."
|
172
185
|
end
|
173
186
|
|
174
|
-
def
|
187
|
+
def failure_message_when_negated
|
175
188
|
"expected #{@actual.current_path.inspect} not to have an exact size of #{@height}, but it did."
|
176
189
|
end
|
177
190
|
|
178
191
|
def description
|
179
192
|
"have an exact height of #{@height}"
|
180
193
|
end
|
194
|
+
|
195
|
+
# RSpec 2 compatibility:
|
196
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
181
197
|
end
|
182
198
|
|
183
199
|
def have_height(height)
|
@@ -201,13 +217,16 @@ module CarrierWave
|
|
201
217
|
"expected #{@actual.current_path.inspect} to have an exact size of #{@width}, but it was #{@actual_width}."
|
202
218
|
end
|
203
219
|
|
204
|
-
def
|
220
|
+
def failure_message_when_negated
|
205
221
|
"expected #{@actual.current_path.inspect} not to have an exact size of #{@width}, but it did."
|
206
222
|
end
|
207
223
|
|
208
224
|
def description
|
209
225
|
"have an exact width of #{@width}"
|
210
226
|
end
|
227
|
+
|
228
|
+
# RSpec 2 compatibility:
|
229
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
211
230
|
end
|
212
231
|
|
213
232
|
def have_width(width)
|
@@ -231,13 +250,16 @@ module CarrierWave
|
|
231
250
|
"expected #{@actual.current_path.inspect} to be no wider than #{@width}, but it was #{@actual_width}."
|
232
251
|
end
|
233
252
|
|
234
|
-
def
|
253
|
+
def failure_message_when_negated
|
235
254
|
"expected #{@actual.current_path.inspect} not to be wider than #{@width}, but it is."
|
236
255
|
end
|
237
256
|
|
238
257
|
def description
|
239
258
|
"have a width less than or equal to #{@width}"
|
240
259
|
end
|
260
|
+
|
261
|
+
# RSpec 2 compatibility:
|
262
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
241
263
|
end
|
242
264
|
|
243
265
|
def be_no_wider_than(width)
|
@@ -261,19 +283,55 @@ module CarrierWave
|
|
261
283
|
"expected #{@actual.current_path.inspect} to be no taller than #{@height}, but it was #{@actual_height}."
|
262
284
|
end
|
263
285
|
|
264
|
-
def
|
286
|
+
def failure_message_when_negated
|
265
287
|
"expected #{@actual.current_path.inspect} not to be taller than #{@height}, but it is."
|
266
288
|
end
|
267
289
|
|
268
290
|
def description
|
269
291
|
"have a height less than or equal to #{@height}"
|
270
292
|
end
|
293
|
+
|
294
|
+
# RSpec 2 compatibility:
|
295
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
271
296
|
end
|
272
297
|
|
273
298
|
def be_no_taller_than(height)
|
274
299
|
BeNoTallerThan.new(height)
|
275
300
|
end
|
276
301
|
|
302
|
+
class BeFormat # :nodoc:
|
303
|
+
def initialize(expected)
|
304
|
+
@expected = expected
|
305
|
+
end
|
306
|
+
|
307
|
+
def matches?(actual)
|
308
|
+
@actual = actual
|
309
|
+
# Satisfy expectation here. Return false or raise an error if it's not met.
|
310
|
+
image = ImageLoader.load_image(@actual.current_path)
|
311
|
+
@actual_expected = image.format
|
312
|
+
!@expected.nil? && @actual_expected.casecmp(@expected).zero?
|
313
|
+
end
|
314
|
+
|
315
|
+
def failure_message
|
316
|
+
"expected #{@actual.current_path.inspect} to have #{@expected} format, but it was #{@actual_expected}."
|
317
|
+
end
|
318
|
+
|
319
|
+
def failure_message_when_negated
|
320
|
+
"expected #{@actual.current_path.inspect} not to have #{@expected} format, but it did."
|
321
|
+
end
|
322
|
+
|
323
|
+
def description
|
324
|
+
"have #{@expected} format"
|
325
|
+
end
|
326
|
+
|
327
|
+
# RSpec 2 compatibility:
|
328
|
+
alias_method :negative_failure_message, :failure_message_when_negated
|
329
|
+
end
|
330
|
+
|
331
|
+
def be_format(expected)
|
332
|
+
BeFormat.new(expected)
|
333
|
+
end
|
334
|
+
|
277
335
|
class ImageLoader # :nodoc:
|
278
336
|
def self.load_image(filename)
|
279
337
|
if defined? ::MiniMagick
|
@@ -303,6 +361,10 @@ module CarrierWave
|
|
303
361
|
image.rows
|
304
362
|
end
|
305
363
|
|
364
|
+
def format
|
365
|
+
image.format
|
366
|
+
end
|
367
|
+
|
306
368
|
def initialize(filename)
|
307
369
|
@image = ::Magick::Image.read(filename).first
|
308
370
|
end
|
@@ -318,6 +380,10 @@ module CarrierWave
|
|
318
380
|
image[:height]
|
319
381
|
end
|
320
382
|
|
383
|
+
def format
|
384
|
+
image[:format]
|
385
|
+
end
|
386
|
+
|
321
387
|
def initialize(filename)
|
322
388
|
@image = ::MiniMagick::Image.open(filename)
|
323
389
|
end
|
@@ -326,4 +392,3 @@ module CarrierWave
|
|
326
392
|
end # Matchers
|
327
393
|
end # Test
|
328
394
|
end # CarrierWave
|
329
|
-
|
data/lib/carrierwave/uploader.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require "carrierwave/uploader/configuration"
|
4
2
|
require "carrierwave/uploader/callbacks"
|
5
3
|
require "carrierwave/uploader/proxy"
|
@@ -13,6 +11,7 @@ require "carrierwave/uploader/extension_whitelist"
|
|
13
11
|
require "carrierwave/uploader/extension_blacklist"
|
14
12
|
require "carrierwave/uploader/content_type_whitelist"
|
15
13
|
require "carrierwave/uploader/content_type_blacklist"
|
14
|
+
require "carrierwave/uploader/file_size"
|
16
15
|
require "carrierwave/uploader/processing"
|
17
16
|
require "carrierwave/uploader/versions"
|
18
17
|
require "carrierwave/uploader/default_url"
|
@@ -57,6 +56,7 @@ module CarrierWave
|
|
57
56
|
include CarrierWave::Uploader::ExtensionBlacklist
|
58
57
|
include CarrierWave::Uploader::ContentTypeWhitelist
|
59
58
|
include CarrierWave::Uploader::ContentTypeBlacklist
|
59
|
+
include CarrierWave::Uploader::FileSize
|
60
60
|
include CarrierWave::Uploader::Processing
|
61
61
|
include CarrierWave::Uploader::Versions
|
62
62
|
include CarrierWave::Uploader::DefaultUrl
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'securerandom'
|
2
2
|
|
3
3
|
module CarrierWave
|
4
4
|
|
@@ -25,9 +25,9 @@ module CarrierWave
|
|
25
25
|
#
|
26
26
|
def self.generate_cache_id
|
27
27
|
[Time.now.utc.to_i,
|
28
|
-
|
29
|
-
'%04d' % (CarrierWave::CacheCounter.increment %
|
30
|
-
'%04d' %
|
28
|
+
SecureRandom.random_number(1_000_000_000_000_000),
|
29
|
+
'%04d' % (CarrierWave::CacheCounter.increment % 10_000),
|
30
|
+
'%04d' % SecureRandom.random_number(10_000)
|
31
31
|
].map(&:to_s).join('-')
|
32
32
|
end
|
33
33
|
|
@@ -38,6 +38,16 @@ module CarrierWave
|
|
38
38
|
include CarrierWave::Uploader::Callbacks
|
39
39
|
include CarrierWave::Uploader::Configuration
|
40
40
|
|
41
|
+
included do
|
42
|
+
prepend Module.new {
|
43
|
+
def initialize(*)
|
44
|
+
super
|
45
|
+
@staged = false
|
46
|
+
end
|
47
|
+
}
|
48
|
+
attr_accessor :staged
|
49
|
+
end
|
50
|
+
|
41
51
|
module ClassMethods
|
42
52
|
|
43
53
|
##
|
@@ -54,13 +64,7 @@ module CarrierWave
|
|
54
64
|
# It's recommended that you keep cache files in one place only.
|
55
65
|
#
|
56
66
|
def clean_cached_files!(seconds=60*60*24)
|
57
|
-
|
58
|
-
time = dir.scan(/(\d+)-\d+-\d+/).first.map { |t| t.to_i }
|
59
|
-
time = Time.at(*time)
|
60
|
-
if time < (Time.now.utc - seconds)
|
61
|
-
FileUtils.rm_rf(dir)
|
62
|
-
end
|
63
|
-
end
|
67
|
+
(cache_storage || storage).new(CarrierWave::Uploader::Base.new).clean_cache!(seconds)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
@@ -86,16 +90,8 @@ module CarrierWave
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def sanitized_file
|
89
|
-
|
90
|
-
|
91
|
-
sanitized = CarrierWave::Storage::Fog.new(self).retrieve!(File.basename(_content.path))
|
92
|
-
sanitized.read if sanitized.exists?
|
93
|
-
|
94
|
-
else
|
95
|
-
sanitized = SanitizedFile.new :tempfile => StringIO.new(file.read),
|
96
|
-
:filename => File.basename(path), :content_type => file.content_type
|
97
|
-
end
|
98
|
-
sanitized
|
93
|
+
ActiveSupport::Deprecation.warn('#sanitized_file is deprecated, use #file instead.')
|
94
|
+
file
|
99
95
|
end
|
100
96
|
|
101
97
|
##
|
@@ -106,7 +102,7 @@ module CarrierWave
|
|
106
102
|
# [String] a cache name, in the format TIMEINT-PID-COUNTER-RND/filename.txt
|
107
103
|
#
|
108
104
|
def cache_name
|
109
|
-
File.join(cache_id, full_original_filename) if cache_id
|
105
|
+
File.join(cache_id, full_original_filename) if cache_id && original_filename
|
110
106
|
end
|
111
107
|
|
112
108
|
##
|
@@ -125,24 +121,31 @@ module CarrierWave
|
|
125
121
|
#
|
126
122
|
# [CarrierWave::FormNotMultipart] if the assigned parameter is a string
|
127
123
|
#
|
128
|
-
def cache!(new_file =
|
124
|
+
def cache!(new_file = file)
|
129
125
|
new_file = CarrierWave::SanitizedFile.new(new_file)
|
126
|
+
return if new_file.empty?
|
130
127
|
|
131
|
-
|
132
|
-
raise CarrierWave::FormNotMultipart if new_file.is_path? && ensure_multipart_form
|
128
|
+
raise CarrierWave::FormNotMultipart if new_file.is_path? && ensure_multipart_form
|
133
129
|
|
134
|
-
|
135
|
-
self.cache_id = CarrierWave.generate_cache_id unless cache_id
|
130
|
+
self.cache_id = CarrierWave.generate_cache_id unless cache_id
|
136
131
|
|
137
|
-
|
138
|
-
|
132
|
+
@staged = true
|
133
|
+
@filename = new_file.filename
|
134
|
+
self.original_filename = new_file.filename
|
139
135
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
136
|
+
begin
|
137
|
+
# first, create a workfile on which we perform processings
|
138
|
+
if move_to_cache
|
139
|
+
@file = new_file.move_to(File.expand_path(workfile_path, root), permissions, directory_permissions)
|
140
|
+
else
|
141
|
+
@file = new_file.copy_to(File.expand_path(workfile_path, root), permissions, directory_permissions)
|
145
142
|
end
|
143
|
+
|
144
|
+
with_callbacks(:cache, @file) do
|
145
|
+
@file = cache_storage.cache!(@file)
|
146
|
+
end
|
147
|
+
ensure
|
148
|
+
FileUtils.rm_rf(workfile_path(''))
|
146
149
|
end
|
147
150
|
end
|
148
151
|
|
@@ -160,15 +163,31 @@ module CarrierWave
|
|
160
163
|
def retrieve_from_cache!(cache_name)
|
161
164
|
with_callbacks(:retrieve_from_cache, cache_name) do
|
162
165
|
self.cache_id, self.original_filename = cache_name.to_s.split('/', 2)
|
166
|
+
@staged = true
|
163
167
|
@filename = original_filename
|
164
|
-
@file =
|
168
|
+
@file = cache_storage.retrieve_from_cache!(full_filename(original_filename))
|
165
169
|
end
|
166
170
|
end
|
167
171
|
|
172
|
+
##
|
173
|
+
# Calculates the path where the cache file should be stored.
|
174
|
+
#
|
175
|
+
# === Parameters
|
176
|
+
#
|
177
|
+
# [for_file (String)] name of the file <optional>
|
178
|
+
#
|
179
|
+
# === Returns
|
180
|
+
#
|
181
|
+
# [String] the cache path
|
182
|
+
#
|
183
|
+
def cache_path(for_file=full_filename(original_filename))
|
184
|
+
File.join(*[cache_dir, @cache_id, for_file].compact)
|
185
|
+
end
|
186
|
+
|
168
187
|
private
|
169
188
|
|
170
|
-
def
|
171
|
-
File.
|
189
|
+
def workfile_path(for_file=original_filename)
|
190
|
+
File.join(CarrierWave.tmp_path, @cache_id, version_name.to_s, for_file)
|
172
191
|
end
|
173
192
|
|
174
193
|
attr_reader :cache_id, :original_filename
|
@@ -179,7 +198,7 @@ module CarrierWave
|
|
179
198
|
def cache_id=(cache_id)
|
180
199
|
# Earlier version used 3 part cache_id. Thus we should allow for
|
181
200
|
# the cache_id to have both 3 part and 4 part formats.
|
182
|
-
raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]+\-[\d]+(\-[\d]{4})?\-[\d]{4}\z/
|
201
|
+
raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A(-)?[\d]+\-[\d]+(\-[\d]{4})?\-[\d]{4}\z/
|
183
202
|
@cache_id = cache_id
|
184
203
|
end
|
185
204
|
|
@@ -188,6 +207,9 @@ module CarrierWave
|
|
188
207
|
@original_filename = filename
|
189
208
|
end
|
190
209
|
|
210
|
+
def cache_storage
|
211
|
+
@cache_storage ||= (self.class.cache_storage || self.class.storage).new(self)
|
212
|
+
end
|
191
213
|
end # Cache
|
192
214
|
end # Uploader
|
193
215
|
end # CarrierWave
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'carrierwave/downloader/base'
|
2
|
+
|
1
3
|
module CarrierWave
|
2
4
|
|
3
5
|
module Uploader
|
@@ -5,7 +7,7 @@ module CarrierWave
|
|
5
7
|
extend ActiveSupport::Concern
|
6
8
|
|
7
9
|
included do
|
8
|
-
class_attribute :_storage, :instance_writer => false
|
10
|
+
class_attribute :_storage, :_cache_storage, :instance_writer => false
|
9
11
|
|
10
12
|
add_config :root
|
11
13
|
add_config :base_path
|
@@ -21,14 +23,17 @@ module CarrierWave
|
|
21
23
|
add_config :move_to_cache
|
22
24
|
add_config :move_to_store
|
23
25
|
add_config :remove_previously_stored_files_after_update
|
26
|
+
add_config :downloader
|
24
27
|
|
25
28
|
# fog
|
29
|
+
add_deprecated_config :fog_provider
|
26
30
|
add_config :fog_attributes
|
27
31
|
add_config :fog_credentials
|
28
32
|
add_config :fog_directory
|
29
33
|
add_config :fog_public
|
30
34
|
add_config :fog_authenticated_url_expiration
|
31
35
|
add_config :fog_use_ssl_for_aws
|
36
|
+
add_config :fog_aws_accelerate
|
32
37
|
|
33
38
|
# Mounting
|
34
39
|
add_config :ignore_integrity_errors
|
@@ -38,6 +43,7 @@ module CarrierWave
|
|
38
43
|
add_config :validate_processing
|
39
44
|
add_config :validate_download
|
40
45
|
add_config :mount_on
|
46
|
+
add_config :cache_only
|
41
47
|
|
42
48
|
# set default values
|
43
49
|
reset_config
|
@@ -69,36 +75,66 @@ module CarrierWave
|
|
69
75
|
# storage MyCustomStorageEngine
|
70
76
|
#
|
71
77
|
def storage(storage = nil)
|
72
|
-
|
73
|
-
|
78
|
+
case storage
|
79
|
+
when Symbol
|
80
|
+
if storage_engine = storage_engines[storage]
|
81
|
+
self._storage = eval storage_engine
|
82
|
+
else
|
83
|
+
raise CarrierWave::UnknownStorageError, "Unknown storage: #{storage}"
|
84
|
+
end
|
85
|
+
when nil
|
86
|
+
storage
|
87
|
+
else
|
88
|
+
self._storage = storage
|
74
89
|
end
|
75
90
|
_storage
|
76
91
|
end
|
77
92
|
alias_method :storage=, :storage
|
78
93
|
|
94
|
+
##
|
95
|
+
# Sets the cache storage engine to be used when storing cache files with this uploader.
|
96
|
+
# Same as .storage except for required methods being #cache!(CarrierWave::SanitizedFile),
|
97
|
+
# #retrieve_from_cache! and #delete_dir!.
|
98
|
+
#
|
99
|
+
# === Parameters
|
100
|
+
#
|
101
|
+
# [storage (Symbol, Class)] The cache storage engine to use for this uploader
|
102
|
+
#
|
103
|
+
# === Returns
|
104
|
+
#
|
105
|
+
# [Class] the cache storage engine to be used with this uploader
|
106
|
+
#
|
107
|
+
# === Examples
|
108
|
+
#
|
109
|
+
# cache_storage :file
|
110
|
+
# cache_storage CarrierWave::Storage::File
|
111
|
+
# cache_storage MyCustomStorageEngine
|
112
|
+
#
|
113
|
+
def cache_storage(storage = false)
|
114
|
+
unless storage == false
|
115
|
+
self._cache_storage = storage.is_a?(Symbol) ? eval(storage_engines[storage]) : storage
|
116
|
+
end
|
117
|
+
_cache_storage
|
118
|
+
end
|
119
|
+
alias_method :cache_storage=, :cache_storage
|
120
|
+
|
79
121
|
def add_config(name)
|
80
122
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
81
|
-
|
82
|
-
# see #1198. This will hopefully no longer be necessary after fog 2.0
|
83
|
-
Fog::Storage.new(fog_credentials) if fog_credentials.present?
|
84
|
-
end
|
123
|
+
@#{name} = nil
|
85
124
|
|
86
125
|
def self.#{name}(value=nil)
|
87
126
|
@#{name} = value if value
|
88
|
-
eager_load_fog(value) if value && '#{name}' == 'fog_credentials'
|
89
127
|
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
|
90
128
|
name = superclass.#{name}
|
91
|
-
return nil if name.nil? && !instance_variable_defined?(
|
129
|
+
return nil if name.nil? && !instance_variable_defined?(:@#{name})
|
92
130
|
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
93
131
|
end
|
94
132
|
|
95
133
|
def self.#{name}=(value)
|
96
|
-
eager_load_fog(value) if '#{name}' == 'fog_credentials'
|
97
134
|
@#{name} = value
|
98
135
|
end
|
99
136
|
|
100
137
|
def #{name}=(value)
|
101
|
-
self.class.eager_load_fog(value) if '#{name}' == 'fog_credentials'
|
102
138
|
@#{name} = value
|
103
139
|
end
|
104
140
|
|
@@ -107,13 +143,33 @@ module CarrierWave
|
|
107
143
|
value = self.class.#{name} unless instance_variable_defined?(:@#{name})
|
108
144
|
if value.instance_of?(Proc)
|
109
145
|
value.arity >= 1 ? value.call(self) : value.call
|
110
|
-
else
|
146
|
+
else
|
111
147
|
value
|
112
148
|
end
|
113
149
|
end
|
114
150
|
RUBY
|
115
151
|
end
|
116
152
|
|
153
|
+
def add_deprecated_config(name)
|
154
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
155
|
+
def self.#{name}(value=nil)
|
156
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.#{name}=(value)
|
160
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
161
|
+
end
|
162
|
+
|
163
|
+
def #{name}=(value)
|
164
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
165
|
+
end
|
166
|
+
|
167
|
+
def #{name}
|
168
|
+
ActiveSupport::Deprecation.warn "##{name} is deprecated and has no effect"
|
169
|
+
end
|
170
|
+
RUBY
|
171
|
+
end
|
172
|
+
|
117
173
|
def configure
|
118
174
|
yield self
|
119
175
|
end
|
@@ -130,17 +186,20 @@ module CarrierWave
|
|
130
186
|
:fog => "CarrierWave::Storage::Fog"
|
131
187
|
}
|
132
188
|
config.storage = :file
|
189
|
+
config.cache_storage = nil
|
133
190
|
config.fog_attributes = {}
|
134
191
|
config.fog_credentials = {}
|
135
192
|
config.fog_public = true
|
136
193
|
config.fog_authenticated_url_expiration = 600
|
137
194
|
config.fog_use_ssl_for_aws = true
|
195
|
+
config.fog_aws_accelerate = false
|
138
196
|
config.store_dir = 'uploads'
|
139
197
|
config.cache_dir = 'uploads/tmp'
|
140
198
|
config.delete_tmp_file_after_storage = true
|
141
199
|
config.move_to_cache = false
|
142
200
|
config.move_to_store = false
|
143
201
|
config.remove_previously_stored_files_after_update = true
|
202
|
+
config.downloader = CarrierWave::Downloader::Base
|
144
203
|
config.ignore_integrity_errors = true
|
145
204
|
config.ignore_processing_errors = true
|
146
205
|
config.ignore_download_errors = true
|
@@ -158,4 +217,3 @@ module CarrierWave
|
|
158
217
|
end
|
159
218
|
end
|
160
219
|
end
|
161
|
-
|