carrierwave 0.5.4 → 0.5.5

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.

@@ -67,7 +67,7 @@ module CarrierWave
67
67
  # [url (String)] The URL where the remote file is stored
68
68
  #
69
69
  def process_uri(uri)
70
- URI.parse(URI.escape(uri))
70
+ URI.parse(URI.escape(URI.unescape(uri)))
71
71
  end
72
72
 
73
73
  end # Download
@@ -8,22 +8,14 @@ module CarrierWave
8
8
  include CarrierWave::Uploader::Callbacks
9
9
 
10
10
  included do
11
+ class_attribute :processors, :instance_writer => false
12
+ self.processors = []
13
+
11
14
  after :cache, :process!
12
15
  end
13
16
 
14
17
  module ClassMethods
15
18
 
16
- ##
17
- # Lists processor callbacks declared
18
- #
19
- # === Returns
20
- #
21
- # [Array[Array[Symbol, Array]]] a list of processor callbacks which have been declared for this uploader
22
- #
23
- def processors
24
- @processors ||= []
25
- end
26
-
27
19
  ##
28
20
  # Adds a processor callback which applies operations as a file is uploaded.
29
21
  # The argument may be the name of any method of the uploader, expressed as a symbol,
@@ -40,6 +32,8 @@ module CarrierWave
40
32
  #
41
33
  # process :sepiatone, :vignette
42
34
  # process :scale => [200, 200]
35
+ # process :scale => [200, 200], :if => :image?
36
+ # process :sepiatone, :if => :image?
43
37
  #
44
38
  # def sepiatone
45
39
  # ...
@@ -52,16 +46,27 @@ module CarrierWave
52
46
  # def scale(height, width)
53
47
  # ...
54
48
  # end
49
+ #
50
+ # def image?
51
+ # ...
52
+ # end
53
+ #
55
54
  # end
56
55
  #
57
56
  def process(*args)
57
+ if !args.first.is_a?(Hash) && args.last.is_a?(Hash)
58
+ conditions = args.pop
59
+ args.map!{ |arg| {arg => []}.merge(conditions) }
60
+ end
61
+
58
62
  args.each do |arg|
59
63
  if arg.is_a?(Hash)
64
+ condition = arg.delete(:if)
60
65
  arg.each do |method, args|
61
- processors.push([method, args])
66
+ self.processors += [[method, args, condition]]
62
67
  end
63
68
  else
64
- processors.push([arg, []])
69
+ self.processors += [[arg, [], nil]]
65
70
  end
66
71
  end
67
72
  end
@@ -73,7 +78,8 @@ module CarrierWave
73
78
  #
74
79
  def process!(new_file=nil)
75
80
  if enable_processing
76
- self.class.processors.each do |method, args|
81
+ self.class.processors.each do |method, args, condition|
82
+ next if condition && !self.send(condition, new_file)
77
83
  self.send(method, *args)
78
84
  end
79
85
  end
@@ -57,6 +57,21 @@ module CarrierWave
57
57
  file.respond_to?(:size) ? file.size : 0
58
58
  end
59
59
 
60
+ ##
61
+ # Return the size of the file when asked for its length
62
+ #
63
+ # === Returns
64
+ #
65
+ # [Integer] size of the file
66
+ #
67
+ # === Note
68
+ #
69
+ # This was added because of the way Rails handles length/size validations in 3.0.6 and above.
70
+ #
71
+ def length
72
+ size
73
+ end
74
+
60
75
  end # Proxy
61
76
  end # Uploader
62
- end # CarrierWave
77
+ end # CarrierWave
@@ -58,11 +58,22 @@ module CarrierWave
58
58
  with_callbacks(:store, new_file) do
59
59
  new_file = storage.store!(@file)
60
60
  @file.delete if delete_tmp_file_after_storage
61
+ delete_cache_id if delete_cache_id_after_storage
61
62
  @file = new_file
62
63
  @cache_id = nil
63
64
  end
64
65
  end
65
66
  end
67
+
68
+ ##
69
+ # Deletes a cache id (tmp dir in cache)
70
+ #
71
+ def delete_cache_id
72
+ if @cache_id
73
+ path = File.join(cache_dir, @cache_id)
74
+ FileUtils.rm_rf(path) if File.exists?(path) && File.directory?(path)
75
+ end
76
+ end
66
77
 
67
78
  ##
68
79
  # Retrieves the file from the storage.
@@ -8,6 +8,22 @@ module CarrierWave
8
8
  include CarrierWave::Uploader::Callbacks
9
9
 
10
10
  included do
11
+ ##
12
+ # Add configuration options for versions
13
+ # class_inheritable_accessor was deprecated in Rails 3.1 and removed for 3.2.
14
+ # class_attribute was added in 3.0, but doesn't support omitting the instance_reader until 3.0.10
15
+ # For max compatibility, always use class_inheritable_accessor when possible
16
+ if respond_to?(:class_inheritable_accessor)
17
+ ActiveSupport::Deprecation.silence do
18
+ class_inheritable_accessor :versions, :version_names, :instance_reader => false, :instance_writer => false
19
+ end
20
+ else
21
+ class_attribute :versions, :version_names, :instance_reader => false, :instance_writer => false
22
+ end
23
+
24
+ self.versions = {}
25
+ self.version_names = []
26
+
11
27
  after :cache, :cache_versions!
12
28
  after :store, :store_versions!
13
29
  after :remove, :remove_versions!
@@ -17,43 +33,78 @@ module CarrierWave
17
33
 
18
34
  module ClassMethods
19
35
 
20
- def version_names
21
- @version_names ||= []
22
- end
23
-
24
36
  ##
25
37
  # Adds a new version to this uploader
26
38
  #
27
39
  # === Parameters
28
40
  #
29
41
  # [name (#to_sym)] name of the version
42
+ # [options (Hash)] optional options hash
30
43
  # [&block (Proc)] a block to eval on this version of the uploader
31
44
  #
32
- def version(name, &block)
45
+ # === Examples
46
+ #
47
+ # class MyUploader < CarrierWave::Uploader::Base
48
+ #
49
+ # version :thumb do
50
+ # process :scale => [200, 200]
51
+ # end
52
+ #
53
+ # version :preview, :if => :image? do
54
+ # process :scale => [200, 200]
55
+ # end
56
+ #
57
+ # end
58
+ #
59
+ def version(name, options = {}, &block)
33
60
  name = name.to_sym
34
61
  unless versions[name]
35
- versions[name] = Class.new(self)
36
- versions[name].version_names.push(*version_names)
37
- versions[name].version_names.push(name)
62
+ uploader = Class.new(self)
63
+ uploader.versions = {}
64
+
65
+ # Define the enable_processing method for versions so they get the
66
+ # value from the parent class unless explicitly overwritten
67
+ uploader.class_eval <<-RUBY, __FILE__, __LINE__ + 1
68
+ def self.enable_processing(value=nil)
69
+ self.enable_processing = value if value
70
+ if !@enable_processing.nil?
71
+ @enable_processing
72
+ else
73
+ superclass.enable_processing
74
+ end
75
+ end
76
+ RUBY
77
+
78
+ # Add the current version hash to class attribute :versions
79
+ current_version = {}
80
+ current_version[name] = {
81
+ :uploader => uploader,
82
+ :options => options
83
+ }
84
+ self.versions = versions.merge(current_version)
85
+
86
+ versions[name][:uploader].version_names += [name]
87
+
38
88
  class_eval <<-RUBY
39
89
  def #{name}
40
90
  versions[:#{name}]
41
91
  end
42
92
  RUBY
93
+ # as the processors get the output from the previous processors as their
94
+ # input we must not stack the processors here
95
+ versions[name][:uploader].processors = versions[name][:uploader].processors.dup
96
+ versions[name][:uploader].processors.clear
43
97
  end
44
- versions[name].class_eval(&block) if block
98
+ versions[name][:uploader].class_eval(&block) if block
45
99
  versions[name]
46
100
  end
47
101
 
48
- ##
49
- # === Returns
50
- #
51
- # [Hash{Symbol => Class}] a list of versions available for this uploader
52
- #
53
- def versions
54
- @versions ||= {}
102
+ def recursively_apply_block_to_versions(&block)
103
+ versions.each do |name, version|
104
+ version[:uploader].class_eval(&block)
105
+ version[:uploader].recursively_apply_block_to_versions(&block)
106
+ end
55
107
  end
56
-
57
108
  end # ClassMethods
58
109
 
59
110
  ##
@@ -66,8 +117,8 @@ module CarrierWave
66
117
  def versions
67
118
  return @versions if @versions
68
119
  @versions = {}
69
- self.class.versions.each do |name, klass|
70
- @versions[name] = klass.new(model, mounted_as)
120
+ self.class.versions.each do |name, version|
121
+ @versions[name] = version[:uploader].new(model, mounted_as)
71
122
  end
72
123
  @versions
73
124
  end
@@ -127,6 +178,13 @@ module CarrierWave
127
178
 
128
179
  private
129
180
 
181
+ def active_versions
182
+ versions.select do |name, uploader|
183
+ condition = self.class.versions[name][:options][:if]
184
+ not condition or send(condition, file)
185
+ end
186
+ end
187
+
130
188
  def full_filename(for_file)
131
189
  [version_name, super(for_file)].compact.join('_')
132
190
  end
@@ -142,14 +200,14 @@ module CarrierWave
142
200
  processed_parent = SanitizedFile.new :tempfile => self.file,
143
201
  :filename => new_file.original_filename
144
202
 
145
- versions.each do |name, v|
203
+ active_versions.each do |name, v|
146
204
  v.send(:cache_id=, cache_id)
147
205
  v.cache!(processed_parent)
148
206
  end
149
207
  end
150
208
 
151
209
  def store_versions!(new_file)
152
- versions.each { |name, v| v.store!(new_file) }
210
+ active_versions.each { |name, v| v.store!(new_file) }
153
211
  end
154
212
 
155
213
  def remove_versions!
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 4
10
- version: 0.5.4
9
+ - 5
10
+ version: 0.5.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonas Nicklas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-18 00:00:00 -04:00
18
+ date: 2011-07-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,26 +29,25 @@ dependencies:
29
29
  - 3
30
30
  - 0
31
31
  version: "3.0"
32
- name: activesupport
33
- type: :runtime
34
32
  prerelease: false
33
+ type: :runtime
35
34
  requirement: *id001
35
+ name: activesupport
36
36
  - !ruby/object:Gem::Dependency
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
39
39
  requirements:
40
- - - "="
40
+ - - ~>
41
41
  - !ruby/object:Gem::Version
42
- hash: 13
42
+ hash: 7
43
43
  segments:
44
44
  - 3
45
45
  - 0
46
- - 5
47
- version: 3.0.5
48
- name: rails
49
- type: :development
46
+ version: "3.0"
50
47
  prerelease: false
48
+ type: :development
51
49
  requirement: *id002
50
+ name: rails
52
51
  - !ruby/object:Gem::Dependency
53
52
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
@@ -60,10 +59,10 @@ dependencies:
60
59
  - 2
61
60
  - 0
62
61
  version: "2.0"
63
- name: rspec
64
- type: :development
65
62
  prerelease: false
63
+ type: :development
66
64
  requirement: *id003
65
+ name: rspec
67
66
  - !ruby/object:Gem::Dependency
68
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
69
68
  none: false
@@ -74,10 +73,10 @@ dependencies:
74
73
  segments:
75
74
  - 0
76
75
  version: "0"
77
- name: excon
78
- type: :development
79
76
  prerelease: false
77
+ type: :development
80
78
  requirement: *id004
79
+ name: excon
81
80
  - !ruby/object:Gem::Dependency
82
81
  version_requirements: &id005 !ruby/object:Gem::Requirement
83
82
  none: false
@@ -88,10 +87,10 @@ dependencies:
88
87
  segments:
89
88
  - 0
90
89
  version: "0"
91
- name: fog
92
- type: :development
93
90
  prerelease: false
91
+ type: :development
94
92
  requirement: *id005
93
+ name: fog
95
94
  - !ruby/object:Gem::Dependency
96
95
  version_requirements: &id006 !ruby/object:Gem::Requirement
97
96
  none: false
@@ -102,10 +101,10 @@ dependencies:
102
101
  segments:
103
102
  - 0
104
103
  version: "0"
105
- name: cucumber
106
- type: :development
107
104
  prerelease: false
105
+ type: :development
108
106
  requirement: *id006
107
+ name: cucumber
109
108
  - !ruby/object:Gem::Dependency
110
109
  version_requirements: &id007 !ruby/object:Gem::Requirement
111
110
  none: false
@@ -116,74 +115,66 @@ dependencies:
116
115
  segments:
117
116
  - 0
118
117
  version: "0"
119
- name: sqlite3
120
- type: :development
121
118
  prerelease: false
119
+ type: :development
122
120
  requirement: *id007
121
+ name: sqlite3
123
122
  - !ruby/object:Gem::Dependency
124
123
  version_requirements: &id008 !ruby/object:Gem::Requirement
125
124
  none: false
126
125
  requirements:
127
- - - "="
126
+ - - ">="
128
127
  - !ruby/object:Gem::Version
129
- hash: 23
128
+ hash: 3
130
129
  segments:
131
- - 1
132
130
  - 0
133
- - 0
134
- version: 1.0.0
135
- name: dm-core
136
- type: :development
131
+ version: "0"
137
132
  prerelease: false
133
+ type: :development
138
134
  requirement: *id008
135
+ name: rmagick
139
136
  - !ruby/object:Gem::Dependency
140
137
  version_requirements: &id009 !ruby/object:Gem::Requirement
141
138
  none: false
142
139
  requirements:
143
- - - "="
140
+ - - ">="
144
141
  - !ruby/object:Gem::Version
145
- hash: 23
142
+ hash: 3
146
143
  segments:
147
- - 1
148
144
  - 0
149
- - 0
150
- version: 1.0.0
151
- name: dm-validations
152
- type: :development
145
+ version: "0"
153
146
  prerelease: false
147
+ type: :development
154
148
  requirement: *id009
149
+ name: RubyInline
155
150
  - !ruby/object:Gem::Dependency
156
151
  version_requirements: &id010 !ruby/object:Gem::Requirement
157
152
  none: false
158
153
  requirements:
159
- - - "="
154
+ - - ">="
160
155
  - !ruby/object:Gem::Version
161
- hash: 23
156
+ hash: 3
162
157
  segments:
163
- - 1
164
158
  - 0
165
- - 0
166
- version: 1.0.0
167
- name: dm-migrations
168
- type: :development
159
+ version: "0"
169
160
  prerelease: false
161
+ type: :development
170
162
  requirement: *id010
163
+ name: image_science
171
164
  - !ruby/object:Gem::Dependency
172
165
  version_requirements: &id011 !ruby/object:Gem::Requirement
173
166
  none: false
174
167
  requirements:
175
- - - "="
168
+ - - ">="
176
169
  - !ruby/object:Gem::Version
177
- hash: 23
170
+ hash: 3
178
171
  segments:
179
- - 1
180
- - 0
181
172
  - 0
182
- version: 1.0.0
183
- name: dm-sqlite-adapter
184
- type: :development
173
+ version: "0"
185
174
  prerelease: false
175
+ type: :development
186
176
  requirement: *id011
177
+ name: mini_magick
187
178
  - !ruby/object:Gem::Dependency
188
179
  version_requirements: &id012 !ruby/object:Gem::Requirement
189
180
  none: false
@@ -194,10 +185,10 @@ dependencies:
194
185
  segments:
195
186
  - 0
196
187
  version: "0"
197
- name: sequel
198
- type: :development
199
188
  prerelease: false
189
+ type: :development
200
190
  requirement: *id012
191
+ name: bson_ext
201
192
  - !ruby/object:Gem::Dependency
202
193
  version_requirements: &id013 !ruby/object:Gem::Requirement
203
194
  none: false
@@ -208,10 +199,10 @@ dependencies:
208
199
  segments:
209
200
  - 0
210
201
  version: "0"
211
- name: rmagick
212
- type: :development
213
202
  prerelease: false
203
+ type: :development
214
204
  requirement: *id013
205
+ name: mongoid
215
206
  - !ruby/object:Gem::Dependency
216
207
  version_requirements: &id014 !ruby/object:Gem::Requirement
217
208
  none: false
@@ -222,10 +213,10 @@ dependencies:
222
213
  segments:
223
214
  - 0
224
215
  version: "0"
225
- name: RubyInline
226
- type: :development
227
216
  prerelease: false
217
+ type: :development
228
218
  requirement: *id014
219
+ name: timecop
229
220
  - !ruby/object:Gem::Dependency
230
221
  version_requirements: &id015 !ruby/object:Gem::Requirement
231
222
  none: false
@@ -236,10 +227,10 @@ dependencies:
236
227
  segments:
237
228
  - 0
238
229
  version: "0"
239
- name: image_science
240
- type: :development
241
230
  prerelease: false
231
+ type: :development
242
232
  requirement: *id015
233
+ name: json
243
234
  - !ruby/object:Gem::Dependency
244
235
  version_requirements: &id016 !ruby/object:Gem::Requirement
245
236
  none: false
@@ -250,10 +241,10 @@ dependencies:
250
241
  segments:
251
242
  - 0
252
243
  version: "0"
253
- name: mini_magick
254
- type: :development
255
244
  prerelease: false
245
+ type: :development
256
246
  requirement: *id016
247
+ name: cloudfiles
257
248
  - !ruby/object:Gem::Dependency
258
249
  version_requirements: &id017 !ruby/object:Gem::Requirement
259
250
  none: false
@@ -264,80 +255,10 @@ dependencies:
264
255
  segments:
265
256
  - 0
266
257
  version: "0"
267
- name: bson_ext
268
- type: :development
269
- prerelease: false
270
- requirement: *id017
271
- - !ruby/object:Gem::Dependency
272
- version_requirements: &id018 !ruby/object:Gem::Requirement
273
- none: false
274
- requirements:
275
- - - ">="
276
- - !ruby/object:Gem::Version
277
- hash: 3
278
- segments:
279
- - 0
280
- version: "0"
281
- name: mongoid
282
- type: :development
283
- prerelease: false
284
- requirement: *id018
285
- - !ruby/object:Gem::Dependency
286
- version_requirements: &id019 !ruby/object:Gem::Requirement
287
- none: false
288
- requirements:
289
- - - ">="
290
- - !ruby/object:Gem::Version
291
- hash: 3
292
- segments:
293
- - 0
294
- version: "0"
295
- name: timecop
296
- type: :development
297
- prerelease: false
298
- requirement: *id019
299
- - !ruby/object:Gem::Dependency
300
- version_requirements: &id020 !ruby/object:Gem::Requirement
301
- none: false
302
- requirements:
303
- - - ">="
304
- - !ruby/object:Gem::Version
305
- hash: 3
306
- segments:
307
- - 0
308
- version: "0"
309
- name: json
310
- type: :development
311
258
  prerelease: false
312
- requirement: *id020
313
- - !ruby/object:Gem::Dependency
314
- version_requirements: &id021 !ruby/object:Gem::Requirement
315
- none: false
316
- requirements:
317
- - - ">="
318
- - !ruby/object:Gem::Version
319
- hash: 3
320
- segments:
321
- - 0
322
- version: "0"
323
- name: cloudfiles
324
259
  type: :development
325
- prerelease: false
326
- requirement: *id021
327
- - !ruby/object:Gem::Dependency
328
- version_requirements: &id022 !ruby/object:Gem::Requirement
329
- none: false
330
- requirements:
331
- - - ">="
332
- - !ruby/object:Gem::Version
333
- hash: 3
334
- segments:
335
- - 0
336
- version: "0"
260
+ requirement: *id017
337
261
  name: sham_rack
338
- type: :development
339
- prerelease: false
340
- requirement: *id022
341
262
  description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
342
263
  email:
343
264
  - jonas.nicklas@gmail.com
@@ -346,16 +267,15 @@ executables: []
346
267
  extensions: []
347
268
 
348
269
  extra_rdoc_files:
349
- - README.rdoc
270
+ - README.md
350
271
  files:
351
272
  - lib/carrierwave/compatibility/paperclip.rb
352
273
  - lib/carrierwave/locale/en.yml
353
274
  - lib/carrierwave/mount.rb
354
275
  - lib/carrierwave/orm/activerecord.rb
355
- - lib/carrierwave/orm/datamapper.rb
356
276
  - lib/carrierwave/orm/mongoid.rb
357
- - lib/carrierwave/orm/sequel.rb
358
277
  - lib/carrierwave/processing/image_science.rb
278
+ - lib/carrierwave/processing/mime_types.rb
359
279
  - lib/carrierwave/processing/mini_magick.rb
360
280
  - lib/carrierwave/processing/rmagick.rb
361
281
  - lib/carrierwave/sanitized_file.rb
@@ -386,7 +306,7 @@ files:
386
306
  - lib/carrierwave.rb
387
307
  - lib/generators/templates/uploader.rb
388
308
  - lib/generators/uploader_generator.rb
389
- - README.rdoc
309
+ - README.md
390
310
  has_rdoc: true
391
311
  homepage: https://github.com/jnicklas/carrierwave
392
312
  licenses: []
@@ -394,7 +314,6 @@ licenses: []
394
314
  post_install_message:
395
315
  rdoc_options:
396
316
  - --main
397
- - README.rdoc
398
317
  require_paths:
399
318
  - lib
400
319
  required_ruby_version: !ruby/object:Gem::Requirement