carrierwave 3.0.0.beta → 3.0.0.rc
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 +4 -4
- data/README.md +104 -64
- data/lib/carrierwave/compatibility/paperclip.rb +4 -2
- data/lib/carrierwave/downloader/base.rb +12 -11
- data/lib/carrierwave/downloader/remote_file.rb +5 -6
- data/lib/carrierwave/locale/en.yml +4 -0
- data/lib/carrierwave/mount.rb +31 -82
- data/lib/carrierwave/mounter.rb +115 -50
- data/lib/carrierwave/orm/activerecord.rb +8 -59
- data/lib/carrierwave/processing/mini_magick.rb +13 -11
- data/lib/carrierwave/processing/rmagick.rb +7 -11
- data/lib/carrierwave/processing/vips.rb +9 -9
- data/lib/carrierwave/sanitized_file.rb +47 -37
- data/lib/carrierwave/storage/abstract.rb +5 -5
- data/lib/carrierwave/storage/file.rb +4 -3
- data/lib/carrierwave/storage/fog.rb +69 -50
- data/lib/carrierwave/test/matchers.rb +11 -7
- data/lib/carrierwave/uploader/cache.rb +17 -9
- data/lib/carrierwave/uploader/callbacks.rb +1 -1
- data/lib/carrierwave/uploader/configuration.rb +8 -4
- data/lib/carrierwave/uploader/dimension.rb +66 -0
- data/lib/carrierwave/uploader/file_size.rb +2 -2
- data/lib/carrierwave/uploader/processing.rb +21 -7
- data/lib/carrierwave/uploader/proxy.rb +16 -3
- data/lib/carrierwave/uploader/store.rb +43 -6
- data/lib/carrierwave/uploader/url.rb +1 -1
- data/lib/carrierwave/uploader/versions.rb +126 -134
- data/lib/carrierwave/uploader.rb +2 -0
- data/lib/carrierwave/utilities/file_name.rb +2 -2
- data/lib/carrierwave/utilities/uri.rb +14 -11
- data/lib/carrierwave/validations/active_model.rb +4 -6
- data/lib/carrierwave/version.rb +1 -1
- data/lib/carrierwave.rb +8 -7
- data/lib/generators/uploader_generator.rb +3 -3
- metadata +18 -3
- /data/lib/generators/templates/{uploader.rb → uploader.rb.erb} +0 -0
@@ -11,7 +11,7 @@ module CarrierWave
|
|
11
11
|
prepend Module.new {
|
12
12
|
def initialize(*)
|
13
13
|
super
|
14
|
-
@file, @filename, @cache_id, @identifier = nil
|
14
|
+
@file, @filename, @cache_id, @identifier, @deduplication_index = nil
|
15
15
|
end
|
16
16
|
}
|
17
17
|
end
|
@@ -34,9 +34,25 @@ module CarrierWave
|
|
34
34
|
@filename
|
35
35
|
end
|
36
36
|
|
37
|
+
##
|
38
|
+
# Returns a filename which doesn't conflict with already-stored files.
|
39
|
+
#
|
40
|
+
# === Returns
|
41
|
+
#
|
42
|
+
# [String] the filename with suffix added for deduplication
|
43
|
+
#
|
44
|
+
def deduplicated_filename
|
45
|
+
return unless filename
|
46
|
+
|
47
|
+
parts = filename.split('.')
|
48
|
+
basename = parts.shift
|
49
|
+
basename.sub!(/ ?\(\d+\)\z/, '')
|
50
|
+
([basename.to_s + (@deduplication_index ? "(#{@deduplication_index})" : '')] + parts).join('.')
|
51
|
+
end
|
52
|
+
|
37
53
|
##
|
38
54
|
# Calculates the path where the file should be stored. If +for_file+ is given, it will be
|
39
|
-
# used as the
|
55
|
+
# used as the identifier, otherwise +CarrierWave::Uploader#identifier+ is assumed.
|
40
56
|
#
|
41
57
|
# === Parameters
|
42
58
|
#
|
@@ -46,7 +62,7 @@ module CarrierWave
|
|
46
62
|
#
|
47
63
|
# [String] the store path
|
48
64
|
#
|
49
|
-
def store_path(for_file=
|
65
|
+
def store_path(for_file=identifier)
|
50
66
|
File.join([store_dir, full_filename(for_file)].compact)
|
51
67
|
end
|
52
68
|
|
@@ -60,7 +76,7 @@ module CarrierWave
|
|
60
76
|
# [new_file (File, IOString, Tempfile)] any kind of file object
|
61
77
|
#
|
62
78
|
def store!(new_file=nil)
|
63
|
-
cache!(new_file) if new_file &&
|
79
|
+
cache!(new_file) if new_file && !cached?
|
64
80
|
if !cache_only && @file && @cache_id
|
65
81
|
with_callbacks(:store, new_file) do
|
66
82
|
new_file = storage.store!(@file)
|
@@ -69,7 +85,8 @@ module CarrierWave
|
|
69
85
|
cache_storage.delete_dir!(cache_path(nil))
|
70
86
|
end
|
71
87
|
@file = new_file
|
72
|
-
@
|
88
|
+
@identifier = storage.identifier
|
89
|
+
@cache_id = @deduplication_index = nil
|
73
90
|
@staged = false
|
74
91
|
end
|
75
92
|
end
|
@@ -89,10 +106,30 @@ module CarrierWave
|
|
89
106
|
end
|
90
107
|
end
|
91
108
|
|
109
|
+
##
|
110
|
+
# Look for a store path which doesn't collide with the given already-stored paths.
|
111
|
+
# It is done by adding a index number as the suffix.
|
112
|
+
# For example, if there's 'image.jpg' and the @deduplication_index is set to 2,
|
113
|
+
# The stored file will be named as 'image(2).jpg'.
|
114
|
+
#
|
115
|
+
# === Parameters
|
116
|
+
#
|
117
|
+
# [current_paths (Array[String])] List of paths for already-stored files
|
118
|
+
#
|
119
|
+
def deduplicate(current_paths)
|
120
|
+
@deduplication_index = nil
|
121
|
+
return unless current_paths.include?(store_path)
|
122
|
+
|
123
|
+
(2..current_paths.size + 1).each do |i|
|
124
|
+
@deduplication_index = i
|
125
|
+
break unless current_paths.include?(store_path)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
92
129
|
private
|
93
130
|
|
94
131
|
def full_filename(for_file)
|
95
|
-
for_file
|
132
|
+
forcing_extension(for_file)
|
96
133
|
end
|
97
134
|
|
98
135
|
def storage
|
@@ -1,6 +1,76 @@
|
|
1
1
|
module CarrierWave
|
2
2
|
module Uploader
|
3
3
|
module Versions
|
4
|
+
class Builder
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@options = {}
|
8
|
+
@blocks = []
|
9
|
+
@klass = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def configure(options, &block)
|
13
|
+
@options.merge!(options)
|
14
|
+
@blocks << block if block
|
15
|
+
@klass = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def build(superclass)
|
19
|
+
return @klass if @klass
|
20
|
+
@klass = Class.new(superclass)
|
21
|
+
superclass.const_set("#{@name.to_s.camelize}VersionUploader", @klass)
|
22
|
+
|
23
|
+
@klass.version_names += [@name]
|
24
|
+
@klass.versions = {}
|
25
|
+
@klass.processors = []
|
26
|
+
@klass.version_options = @options
|
27
|
+
@klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
28
|
+
# Regardless of what is set in the parent uploader, do not enforce the
|
29
|
+
# move_to_cache config option on versions because it moves the original
|
30
|
+
# file to the version's target file.
|
31
|
+
#
|
32
|
+
# If you want to enforce this setting on versions, override this method
|
33
|
+
# in each version:
|
34
|
+
#
|
35
|
+
# version :thumb do
|
36
|
+
# def move_to_cache
|
37
|
+
# true
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
def move_to_cache
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
# Need to rely on the parent version's identifier, as versions don't have its own one.
|
46
|
+
def identifier
|
47
|
+
parent_version.identifier
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
@blocks.each { |block| @klass.class_eval(&block) }
|
51
|
+
@klass
|
52
|
+
end
|
53
|
+
|
54
|
+
def deep_dup
|
55
|
+
other = dup
|
56
|
+
other.instance_variable_set(:@blocks, @blocks.dup)
|
57
|
+
other
|
58
|
+
end
|
59
|
+
|
60
|
+
def method_missing(name, *args)
|
61
|
+
super
|
62
|
+
rescue NoMethodError => e
|
63
|
+
raise e.exception <<~ERROR
|
64
|
+
#{e.message}
|
65
|
+
If you're trying to configure a version, do it inside a block like `version(:thumb) { self.#{name} #{args.map(&:inspect).join(', ')} }`.
|
66
|
+
ERROR
|
67
|
+
end
|
68
|
+
|
69
|
+
def respond_to_missing?(*)
|
70
|
+
super
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
4
74
|
extend ActiveSupport::Concern
|
5
75
|
|
6
76
|
include CarrierWave::Uploader::Callbacks
|
@@ -11,9 +81,8 @@ module CarrierWave
|
|
11
81
|
self.versions = {}
|
12
82
|
self.version_names = []
|
13
83
|
|
14
|
-
attr_accessor :
|
84
|
+
attr_accessor :parent_version
|
15
85
|
|
16
|
-
after :cache, :assign_parent_cache_id
|
17
86
|
after :cache, :cache_versions!
|
18
87
|
after :store, :store_versions!
|
19
88
|
after :remove, :remove_versions!
|
@@ -23,7 +92,7 @@ module CarrierWave
|
|
23
92
|
prepend Module.new {
|
24
93
|
def initialize(*)
|
25
94
|
super
|
26
|
-
@versions
|
95
|
+
@versions = nil
|
27
96
|
end
|
28
97
|
}
|
29
98
|
end
|
@@ -59,76 +128,25 @@ module CarrierWave
|
|
59
128
|
#
|
60
129
|
def version(name, options = {}, &block)
|
61
130
|
name = name.to_sym
|
62
|
-
|
131
|
+
versions[name] ||= Builder.new(name)
|
132
|
+
versions[name].configure(options, &block)
|
63
133
|
|
64
|
-
|
65
|
-
|
66
|
-
|
134
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
135
|
+
def #{name}
|
136
|
+
versions[:#{name}]
|
137
|
+
end
|
138
|
+
RUBY
|
67
139
|
|
68
|
-
|
69
|
-
versions.each do |name, version|
|
70
|
-
version.class_eval(&block)
|
71
|
-
version.recursively_apply_block_to_versions(&block)
|
72
|
-
end
|
140
|
+
versions[name]
|
73
141
|
end
|
74
142
|
|
75
143
|
private
|
76
144
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
uploader.version_names += [name]
|
82
|
-
uploader.versions = {}
|
83
|
-
uploader.processors = []
|
84
|
-
uploader.version_options = options
|
85
|
-
|
86
|
-
uploader.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
87
|
-
# Define the enable_processing method for versions so they get the
|
88
|
-
# value from the parent class unless explicitly overwritten
|
89
|
-
def self.enable_processing(value=nil)
|
90
|
-
self.enable_processing = value if value
|
91
|
-
if defined?(@enable_processing) && !@enable_processing.nil?
|
92
|
-
@enable_processing
|
93
|
-
else
|
94
|
-
superclass.enable_processing
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Regardless of what is set in the parent uploader, do not enforce the
|
99
|
-
# move_to_cache config option on versions because it moves the original
|
100
|
-
# file to the version's target file.
|
101
|
-
#
|
102
|
-
# If you want to enforce this setting on versions, override this method
|
103
|
-
# in each version:
|
104
|
-
#
|
105
|
-
# version :thumb do
|
106
|
-
# def move_to_cache
|
107
|
-
# true
|
108
|
-
# end
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
def move_to_cache
|
112
|
-
false
|
113
|
-
end
|
114
|
-
RUBY
|
115
|
-
|
116
|
-
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
117
|
-
def #{name}
|
118
|
-
versions[:#{name}]
|
119
|
-
end
|
120
|
-
RUBY
|
121
|
-
else
|
122
|
-
uploader = Class.new(versions[name])
|
123
|
-
const_set("Uploader#{uploader.object_id}".tr('-', '_'), uploader)
|
124
|
-
uploader.processors = []
|
125
|
-
uploader.version_options = uploader.version_options.merge(options)
|
126
|
-
end
|
127
|
-
|
128
|
-
# Add the current version hash to class attribute :versions
|
129
|
-
self.versions = versions.merge(name => uploader)
|
145
|
+
def inherited(subclass)
|
146
|
+
# To prevent subclass version changes affecting superclass versions
|
147
|
+
subclass.versions = versions.deep_dup
|
148
|
+
super
|
130
149
|
end
|
131
|
-
|
132
150
|
end # ClassMethods
|
133
151
|
|
134
152
|
##
|
@@ -142,7 +160,7 @@ module CarrierWave
|
|
142
160
|
return @versions if @versions
|
143
161
|
@versions = {}
|
144
162
|
self.class.versions.each do |name, version|
|
145
|
-
@versions[name] = version.new(model, mounted_as)
|
163
|
+
@versions[name] = version.build(self.class).new(model, mounted_as)
|
146
164
|
@versions[name].parent_version = self
|
147
165
|
end
|
148
166
|
@versions
|
@@ -170,22 +188,21 @@ module CarrierWave
|
|
170
188
|
def version_exists?(name)
|
171
189
|
name = name.to_sym
|
172
190
|
|
173
|
-
return false unless
|
191
|
+
return false unless versions.has_key?(name)
|
174
192
|
|
175
|
-
|
176
|
-
|
177
|
-
unless_condition = self.class.versions[name].version_options[:unless]
|
193
|
+
if_condition = versions[name].class.version_options[:if]
|
194
|
+
unless_condition = versions[name].class.version_options[:unless]
|
178
195
|
|
179
|
-
if
|
180
|
-
if
|
196
|
+
if if_condition
|
197
|
+
if if_condition.respond_to?(:call)
|
181
198
|
if_condition.call(self, :version => name, :file => file)
|
182
199
|
else
|
183
200
|
send(if_condition, file)
|
184
201
|
end
|
185
|
-
elsif
|
186
|
-
if
|
202
|
+
elsif unless_condition
|
203
|
+
if unless_condition.respond_to?(:call)
|
187
204
|
!unless_condition.call(self, :version => name, :file => file)
|
188
|
-
|
205
|
+
else
|
189
206
|
!send(unless_condition, file)
|
190
207
|
end
|
191
208
|
else
|
@@ -193,6 +210,17 @@ module CarrierWave
|
|
193
210
|
end
|
194
211
|
end
|
195
212
|
|
213
|
+
##
|
214
|
+
# Copies the parent's cache_id when caching a version file.
|
215
|
+
# This behavior is not essential but it makes easier to understand
|
216
|
+
# that the cached files are generated by the single upload attempt.
|
217
|
+
#
|
218
|
+
def cache!(*args)
|
219
|
+
self.cache_id = parent_version.cache_id if parent_version
|
220
|
+
|
221
|
+
super
|
222
|
+
end
|
223
|
+
|
196
224
|
##
|
197
225
|
# When given a version name as a parameter, will return the url for that version
|
198
226
|
# This also works with nested versions.
|
@@ -234,60 +262,25 @@ module CarrierWave
|
|
234
262
|
# versions if their parameters somehow have changed.
|
235
263
|
#
|
236
264
|
def recreate_versions!(*names)
|
237
|
-
#
|
238
|
-
#
|
239
|
-
# processing a cached file
|
240
|
-
#
|
241
|
-
# The call to store! will trigger the necessary callbacks to both
|
242
|
-
# process this version and all sub-versions
|
265
|
+
# As well as specified versions, we need to reprocess versions
|
266
|
+
# that are the source of another version.
|
243
267
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
reset_versions_to_cache_and_store
|
248
|
-
else
|
249
|
-
cache! if !cached?
|
250
|
-
store!
|
268
|
+
self.cache_id = CarrierWave.generate_cache_id
|
269
|
+
derived_versions.each do |name, v|
|
270
|
+
v.cache!(file) if names.empty? || !(v.descendant_version_names & names).empty?
|
251
271
|
end
|
252
|
-
|
253
|
-
|
254
|
-
private
|
255
|
-
|
256
|
-
def set_versions_to_cache_and_store(names)
|
257
|
-
@versions_to_cache = source_versions_of(names)
|
258
|
-
@versions_to_store = active_versions_with_names_in(@versions_to_cache + names)
|
259
|
-
end
|
260
|
-
|
261
|
-
def reset_versions_to_cache_and_store
|
262
|
-
@versions_to_cache, @versions_to_store = nil, nil
|
263
|
-
end
|
264
|
-
|
265
|
-
def versions_to_cache
|
266
|
-
@versions_to_cache || dependent_versions
|
267
|
-
end
|
268
|
-
|
269
|
-
def versions_to_store
|
270
|
-
@versions_to_store || active_versions
|
271
|
-
end
|
272
|
-
|
273
|
-
def source_versions_of(requested_names)
|
274
|
-
versions.inject([]) do |sources, (name, uploader)|
|
275
|
-
next sources unless requested_names.include?(name)
|
276
|
-
next sources unless source_name = uploader.class.version_options[:from_version]
|
277
|
-
|
278
|
-
sources << [source_name, versions[source_name]]
|
279
|
-
end.uniq
|
280
|
-
end
|
281
|
-
|
282
|
-
def active_versions_with_names_in(names)
|
283
|
-
active_versions.select do |pretendent_name, uploader|
|
284
|
-
names.include?(pretendent_name)
|
272
|
+
active_versions.each do |name, v|
|
273
|
+
v.store! if names.empty? || names.include?(name)
|
285
274
|
end
|
275
|
+
ensure
|
276
|
+
@cache_id = nil
|
286
277
|
end
|
287
278
|
|
288
|
-
|
289
|
-
|
290
|
-
|
279
|
+
protected
|
280
|
+
|
281
|
+
def descendant_version_names
|
282
|
+
[version_name] + derived_versions.flat_map do |name, version|
|
283
|
+
version.descendant_version_names
|
291
284
|
end
|
292
285
|
end
|
293
286
|
|
@@ -297,16 +290,18 @@ module CarrierWave
|
|
297
290
|
end
|
298
291
|
end
|
299
292
|
|
300
|
-
|
293
|
+
private
|
294
|
+
|
295
|
+
def derived_versions
|
301
296
|
active_versions.reject do |name, v|
|
302
297
|
v.class.version_options[:from_version]
|
303
|
-
end.to_a +
|
298
|
+
end.to_a + active_sibling_versions.select do |name, v|
|
304
299
|
v.class.version_options[:from_version] == self.class.version_names.last
|
305
300
|
end.to_a
|
306
301
|
end
|
307
302
|
|
308
|
-
def
|
309
|
-
parent_version
|
303
|
+
def active_sibling_versions
|
304
|
+
parent_version&.active_versions || []
|
310
305
|
end
|
311
306
|
|
312
307
|
def full_filename(for_file)
|
@@ -318,14 +313,11 @@ module CarrierWave
|
|
318
313
|
end
|
319
314
|
|
320
315
|
def cache_versions!(new_file)
|
321
|
-
|
322
|
-
v.send(:cache_id=, @cache_id)
|
323
|
-
v.cache!(new_file)
|
324
|
-
end
|
316
|
+
derived_versions.each { |name, v| v.cache!(new_file) }
|
325
317
|
end
|
326
318
|
|
327
319
|
def store_versions!(new_file)
|
328
|
-
|
320
|
+
active_versions.each { |name, v| v.store!(new_file) }
|
329
321
|
end
|
330
322
|
|
331
323
|
def remove_versions!
|
data/lib/carrierwave/uploader.rb
CHANGED
@@ -12,6 +12,7 @@ require "carrierwave/uploader/extension_denylist"
|
|
12
12
|
require "carrierwave/uploader/content_type_allowlist"
|
13
13
|
require "carrierwave/uploader/content_type_denylist"
|
14
14
|
require "carrierwave/uploader/file_size"
|
15
|
+
require "carrierwave/uploader/dimension"
|
15
16
|
require "carrierwave/uploader/processing"
|
16
17
|
require "carrierwave/uploader/versions"
|
17
18
|
require "carrierwave/uploader/default_url"
|
@@ -57,6 +58,7 @@ module CarrierWave
|
|
57
58
|
include CarrierWave::Uploader::ContentTypeAllowlist
|
58
59
|
include CarrierWave::Uploader::ContentTypeDenylist
|
59
60
|
include CarrierWave::Uploader::FileSize
|
61
|
+
include CarrierWave::Uploader::Dimension
|
60
62
|
include CarrierWave::Uploader::Processing
|
61
63
|
include CarrierWave::Uploader::Versions
|
62
64
|
include CarrierWave::Uploader::DefaultUrl
|
@@ -25,7 +25,7 @@ module CarrierWave
|
|
25
25
|
split_extension(filename)[1] if filename
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
private
|
29
29
|
|
30
30
|
def split_extension(filename)
|
31
31
|
# regular expressions to try for identifying extensions
|
@@ -40,7 +40,7 @@ module CarrierWave
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
43
|
+
[filename, ""] # In case we weren't able to split the extension
|
44
44
|
end
|
45
45
|
end # FileName
|
46
46
|
end # Utilities
|
@@ -3,20 +3,23 @@ require 'uri'
|
|
3
3
|
module CarrierWave
|
4
4
|
module Utilities
|
5
5
|
module Uri
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
# based on Ruby < 2.0's URI.encode
|
7
|
+
PATH_SAFE = URI::REGEXP::PATTERN::UNRESERVED + '\/'
|
8
|
+
PATH_UNSAFE = Regexp.new("[^#{PATH_SAFE}]", false)
|
9
|
+
NON_ASCII = /[^[:ascii:]]/.freeze
|
9
10
|
|
10
11
|
private
|
12
|
+
|
11
13
|
def encode_path(path)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
URI::DEFAULT_PARSER.escape(path, PATH_UNSAFE)
|
15
|
+
end
|
16
|
+
|
17
|
+
def encode_non_ascii(str)
|
18
|
+
URI::DEFAULT_PARSER.escape(str, NON_ASCII)
|
19
|
+
end
|
20
|
+
|
21
|
+
def decode_uri(str)
|
22
|
+
URI::DEFAULT_PARSER.unescape(str)
|
20
23
|
end
|
21
24
|
end # Uri
|
22
25
|
end # Utilities
|
@@ -12,8 +12,7 @@ module CarrierWave
|
|
12
12
|
|
13
13
|
def validate_each(record, attribute, value)
|
14
14
|
record.__send__("#{attribute}_processing_errors").each do |e|
|
15
|
-
message
|
16
|
-
record.errors.add(attribute, message)
|
15
|
+
record.errors.add(attribute, :carrierwave_processing_error, message: (e.message != e.class.to_s) && e.message)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
@@ -22,8 +21,7 @@ module CarrierWave
|
|
22
21
|
|
23
22
|
def validate_each(record, attribute, value)
|
24
23
|
record.__send__("#{attribute}_integrity_errors").each do |e|
|
25
|
-
message
|
26
|
-
record.errors.add(attribute, message)
|
24
|
+
record.errors.add(attribute, :carrierwave_integrity_error, message: (e.message != e.class.to_s) && e.message)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -32,8 +30,7 @@ module CarrierWave
|
|
32
30
|
|
33
31
|
def validate_each(record, attribute, value)
|
34
32
|
record.__send__("#{attribute}_download_errors").each do |e|
|
35
|
-
message
|
36
|
-
record.errors.add(attribute, message)
|
33
|
+
record.errors.add(attribute, :carrierwave_download_error, message: (e.message != e.class.to_s) && e.message)
|
37
34
|
end
|
38
35
|
end
|
39
36
|
end
|
@@ -58,6 +55,7 @@ module CarrierWave
|
|
58
55
|
def validates_processing_of(*attr_names)
|
59
56
|
validates_with ProcessingValidator, _merge_attributes(attr_names)
|
60
57
|
end
|
58
|
+
|
61
59
|
#
|
62
60
|
##
|
63
61
|
# Makes the record invalid if the remote file couldn't be downloaded
|
data/lib/carrierwave/version.rb
CHANGED
data/lib/carrierwave.rb
CHANGED
@@ -75,13 +75,14 @@ elsif defined?(Sinatra)
|
|
75
75
|
CarrierWave.root = File.join(PADRINO_ROOT, "public")
|
76
76
|
else
|
77
77
|
|
78
|
-
CarrierWave.root =
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
CarrierWave.root =
|
79
|
+
if Sinatra::Application.respond_to?(:public_folder)
|
80
|
+
# Sinatra >= 1.3
|
81
|
+
Sinatra::Application.public_folder
|
82
|
+
else
|
83
|
+
# Sinatra < 1.3
|
84
|
+
Sinatra::Application.public
|
85
|
+
end
|
85
86
|
end
|
86
87
|
end
|
87
88
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class UploaderGenerator < Rails::Generators::NamedBase
|
2
|
-
source_root File.expand_path(
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
3
|
|
4
4
|
def create_uploader_file
|
5
|
-
template "uploader.rb", File.join('app/uploaders', class_path, "#{file_name}_uploader.rb")
|
5
|
+
template "uploader.rb.erb", File.join('app/uploaders', class_path, "#{file_name}_uploader.rb")
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.28'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.28'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
168
|
name: webmock
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,6 +360,7 @@ files:
|
|
346
360
|
- lib/carrierwave/uploader/content_type_allowlist.rb
|
347
361
|
- lib/carrierwave/uploader/content_type_denylist.rb
|
348
362
|
- lib/carrierwave/uploader/default_url.rb
|
363
|
+
- lib/carrierwave/uploader/dimension.rb
|
349
364
|
- lib/carrierwave/uploader/download.rb
|
350
365
|
- lib/carrierwave/uploader/extension_allowlist.rb
|
351
366
|
- lib/carrierwave/uploader/extension_denylist.rb
|
@@ -363,7 +378,7 @@ files:
|
|
363
378
|
- lib/carrierwave/utilities/uri.rb
|
364
379
|
- lib/carrierwave/validations/active_model.rb
|
365
380
|
- lib/carrierwave/version.rb
|
366
|
-
- lib/generators/templates/uploader.rb
|
381
|
+
- lib/generators/templates/uploader.rb.erb
|
367
382
|
- lib/generators/uploader_generator.rb
|
368
383
|
homepage: https://github.com/carrierwaveuploader/carrierwave
|
369
384
|
licenses:
|
File without changes
|