carrierwave 0.5.3 → 0.5.4

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.

data/README.rdoc CHANGED
@@ -125,6 +125,31 @@ make the record invalid instead. Otherwise, an error is raised.
125
125
  end
126
126
  end
127
127
 
128
+ === Validating Uploads
129
+
130
+ Standard active model validations can be used to ensure a file is uploaded.
131
+
132
+ mount_uploader :avatar, AvatarUploader
133
+
134
+ validate_presence_of :avatar
135
+
136
+ CarrierWave also supplies additional validations, such as validating the integrity of an uploaded file.
137
+
138
+ validates_integrity_of :avatar
139
+
140
+ or validating that the file was sucessfully processed
141
+
142
+ validates_processing_of :avatar
143
+
144
+ The validations use translated error messages and can be changed using i18n localization
145
+
146
+ en:
147
+ errors:
148
+ messages:
149
+ carrierwave_processing_error: failed to be processed
150
+ carrierwave_integrity_error: is not an allowed file type
151
+
152
+
128
153
  === Filenames and unicode chars
129
154
 
130
155
  Another security issue you should care for is the file names (see
@@ -366,7 +391,8 @@ Fog[http://github.com/geemus/fog] is used to support Amazon S3. Ensure you have
366
391
  gem install fog
367
392
 
368
393
  You'll need to provide your fog_credentials and a fog_directory (also known as a bucket) in an initializer.
369
- You can also pass in additional options, as documented fully in lib/storage/fog.rb. Here's a full example:
394
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
395
+ You can also pass in additional options, as documented fully in lib/carrierwave/storage/fog.rb. Here's a full example:
370
396
 
371
397
  CarrierWave.configure do |config|
372
398
  config.fog_credentials = {
@@ -395,7 +421,8 @@ Fog[http://github.com/geemus/fog] is used to support Rackspace Cloud Files. Ensu
395
421
 
396
422
  gem install fog
397
423
 
398
- You'll need to configure a directory (also known as a container), username and api key like this in an initializer:
424
+ You'll need to configure a directory (also known as a container), username and api key in the initializer.
425
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
399
426
 
400
427
  CarrierWave.configure do |config|
401
428
  config.fog_credentials = {
@@ -427,7 +454,8 @@ Fog[http://github.com/geemus/fog] is used to support Google Storage for Develope
427
454
 
428
455
  gem install fog
429
456
 
430
- You'll need to configure a directory (also known as a bucket), access key id and secret access key like this in an initializer:
457
+ You'll need to configure a directory (also known as a bucket), access key id and secret access key in the initialiazer.
458
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
431
459
 
432
460
  CarrierWave.configure do |config|
433
461
  config.fog_credentials = {
data/lib/carrierwave.rb CHANGED
@@ -4,6 +4,7 @@ require 'fileutils'
4
4
  require 'active_support/core_ext/object/blank'
5
5
  require 'active_support/core_ext/class/attribute'
6
6
  require 'active_support/concern'
7
+ require 'active_support/memoizable'
7
8
 
8
9
  module CarrierWave
9
10
 
@@ -256,6 +256,7 @@ module CarrierWave
256
256
  # this is an internal class, used by CarrierWave::Mount so that
257
257
  # we don't pollute the model with a lot of methods.
258
258
  class Mounter #:nodoc:
259
+ extend ActiveSupport::Memoizable
259
260
 
260
261
  attr_reader :column, :record, :remote_url, :integrity_error, :processing_error
261
262
  attr_accessor :remove
@@ -346,6 +347,7 @@ module CarrierWave
346
347
  def option(name)
347
348
  record.class.uploader_option(column, name)
348
349
  end
350
+ memoize :option
349
351
 
350
352
  def serialization_column
351
353
  option(:mount_on) || column
@@ -17,7 +17,7 @@ module CarrierWave
17
17
  # You need to setup some options to configure your usage:
18
18
  #
19
19
  # [:fog_credentials] credentials for service
20
- # [:fog_directory] specifies name of directory to store data in
20
+ # [:fog_directory] specifies name of directory to store data in, assumed to already exist
21
21
  #
22
22
  # [:fog_attributes] (optional) additional attributes to set on files
23
23
  # [:fog_host] (optional) non-default host to serve files from
@@ -174,7 +174,8 @@ module CarrierWave
174
174
  # [Boolean] true for success or raises error
175
175
  #
176
176
  def delete
177
- file.destroy
177
+ # avoid a get by just using local reference
178
+ directory.files.new(:key => path).destroy
178
179
  end
179
180
 
180
181
  ##
@@ -247,8 +248,22 @@ module CarrierWave
247
248
  if host = @uploader.fog_host
248
249
  "#{host}/#{path}"
249
250
  else
250
- # avoid a get by just using local reference
251
- directory.files.new(:key => path).public_url
251
+ # AWS/Google optimized for speed over correctness
252
+ case @uploader.fog_credentials[:provider]
253
+ when 'AWS'
254
+ # if directory is a valid subdomain, use that style for access
255
+ if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\.(?![\.\-])|\-(?![\.])){1,61}[a-z0-9]$/
256
+ "https://#{@uploader.fog_directory}.s3.amazonaws.com/#{path}"
257
+ else
258
+ # directory is not a valid subdomain, so use path style for access
259
+ "https://s3.amazonaws.com/#{@uploader.fog_directory}/#{path}"
260
+ end
261
+ when 'Google'
262
+ "https://commondatastorage.googleapis.com/#{@uploader.fog_directory}/#{path}"
263
+ else
264
+ # avoid a get by just using local reference
265
+ directory.files.new(:key => path).public_url
266
+ end
252
267
  end
253
268
  end
254
269
 
@@ -283,7 +298,7 @@ module CarrierWave
283
298
  end
284
299
 
285
300
  ##
286
- # lookup directory containing file
301
+ # local reference to directory containing file
287
302
  #
288
303
  # === Returns
289
304
  #
@@ -291,7 +306,7 @@ module CarrierWave
291
306
  #
292
307
  def directory
293
308
  @directory ||= begin
294
- connection.directories.get(@uploader.fog_directory) || connection.directories.create(
309
+ connection.directories.new(
295
310
  :key => @uploader.fog_directory,
296
311
  :public => @uploader.fog_public
297
312
  )
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  end
@@ -8,7 +8,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
8
8
 
9
9
  # Choose what kind of storage to use for this uploader:
10
10
  storage :file
11
- # storage :s3
11
+ # storage :fog
12
12
 
13
13
  # Override the directory where uploaded files will be stored.
14
14
  # This is a sensible default for uploaders that are meant to be mounted:
@@ -40,6 +40,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
40
40
  # end
41
41
 
42
42
  # Override the filename of the uploaded files:
43
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
43
44
  # def filename
44
45
  # "something.jpg" if original_filename
45
46
  # 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: 13
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 3
10
- version: 0.5.3
9
+ - 4
10
+ version: 0.5.4
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-03-22 00:00:00 +00:00
18
+ date: 2011-05-18 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,10 +29,10 @@ dependencies:
29
29
  - 3
30
30
  - 0
31
31
  version: "3.0"
32
- prerelease: false
32
+ name: activesupport
33
33
  type: :runtime
34
+ prerelease: false
34
35
  requirement: *id001
35
- name: activesupport
36
36
  - !ruby/object:Gem::Dependency
37
37
  version_requirements: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -45,90 +45,81 @@ dependencies:
45
45
  - 0
46
46
  - 5
47
47
  version: 3.0.5
48
- prerelease: false
48
+ name: rails
49
49
  type: :development
50
+ prerelease: false
50
51
  requirement: *id002
51
- name: rails
52
52
  - !ruby/object:Gem::Dependency
53
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
- - - "="
56
+ - - ~>
57
57
  - !ruby/object:Gem::Version
58
- hash: 27
58
+ hash: 3
59
59
  segments:
60
- - 1
61
- - 3
60
+ - 2
62
61
  - 0
63
- version: 1.3.0
64
- prerelease: false
62
+ version: "2.0"
63
+ name: rspec
65
64
  type: :development
65
+ prerelease: false
66
66
  requirement: *id003
67
- name: rspec
68
67
  - !ruby/object:Gem::Dependency
69
68
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
72
- - - "="
71
+ - - ">="
73
72
  - !ruby/object:Gem::Version
74
- hash: 1
73
+ hash: 3
75
74
  segments:
76
75
  - 0
77
- - 7
78
- - 1
79
- version: 0.7.1
80
- prerelease: false
76
+ version: "0"
77
+ name: excon
81
78
  type: :development
79
+ prerelease: false
82
80
  requirement: *id004
83
- name: fog
84
81
  - !ruby/object:Gem::Dependency
85
82
  version_requirements: &id005 !ruby/object:Gem::Requirement
86
83
  none: false
87
84
  requirements:
88
- - - "="
85
+ - - ">="
89
86
  - !ruby/object:Gem::Version
90
- hash: 53
87
+ hash: 3
91
88
  segments:
92
89
  - 0
93
- - 8
94
- - 5
95
- version: 0.8.5
96
- prerelease: false
90
+ version: "0"
91
+ name: fog
97
92
  type: :development
93
+ prerelease: false
98
94
  requirement: *id005
99
- name: cucumber
100
95
  - !ruby/object:Gem::Dependency
101
96
  version_requirements: &id006 !ruby/object:Gem::Requirement
102
97
  none: false
103
98
  requirements:
104
- - - "="
99
+ - - ">="
105
100
  - !ruby/object:Gem::Version
106
- hash: 29
101
+ hash: 3
107
102
  segments:
108
- - 1
109
- - 3
110
- - 3
111
- version: 1.3.3
112
- prerelease: false
103
+ - 0
104
+ version: "0"
105
+ name: cucumber
113
106
  type: :development
107
+ prerelease: false
114
108
  requirement: *id006
115
- name: sqlite3
116
109
  - !ruby/object:Gem::Dependency
117
110
  version_requirements: &id007 !ruby/object:Gem::Requirement
118
111
  none: false
119
112
  requirements:
120
- - - "="
113
+ - - ">="
121
114
  - !ruby/object:Gem::Version
122
- hash: 23
115
+ hash: 3
123
116
  segments:
124
- - 1
125
- - 0
126
117
  - 0
127
- version: 1.0.0
128
- prerelease: false
118
+ version: "0"
119
+ name: sqlite3
129
120
  type: :development
121
+ prerelease: false
130
122
  requirement: *id007
131
- name: dm-core
132
123
  - !ruby/object:Gem::Dependency
133
124
  version_requirements: &id008 !ruby/object:Gem::Requirement
134
125
  none: false
@@ -141,10 +132,10 @@ dependencies:
141
132
  - 0
142
133
  - 0
143
134
  version: 1.0.0
144
- prerelease: false
135
+ name: dm-core
145
136
  type: :development
137
+ prerelease: false
146
138
  requirement: *id008
147
- name: dm-validations
148
139
  - !ruby/object:Gem::Dependency
149
140
  version_requirements: &id009 !ruby/object:Gem::Requirement
150
141
  none: false
@@ -157,10 +148,10 @@ dependencies:
157
148
  - 0
158
149
  - 0
159
150
  version: 1.0.0
160
- prerelease: false
151
+ name: dm-validations
161
152
  type: :development
153
+ prerelease: false
162
154
  requirement: *id009
163
- name: dm-migrations
164
155
  - !ruby/object:Gem::Dependency
165
156
  version_requirements: &id010 !ruby/object:Gem::Requirement
166
157
  none: false
@@ -173,187 +164,180 @@ dependencies:
173
164
  - 0
174
165
  - 0
175
166
  version: 1.0.0
176
- prerelease: false
167
+ name: dm-migrations
177
168
  type: :development
169
+ prerelease: false
178
170
  requirement: *id010
179
- name: dm-sqlite-adapter
180
171
  - !ruby/object:Gem::Dependency
181
172
  version_requirements: &id011 !ruby/object:Gem::Requirement
182
173
  none: false
183
174
  requirements:
184
175
  - - "="
185
176
  - !ruby/object:Gem::Version
186
- hash: 63
177
+ hash: 23
187
178
  segments:
188
- - 3
189
- - 14
179
+ - 1
190
180
  - 0
191
- version: 3.14.0
192
- prerelease: false
181
+ - 0
182
+ version: 1.0.0
183
+ name: dm-sqlite-adapter
193
184
  type: :development
185
+ prerelease: false
194
186
  requirement: *id011
195
- name: sequel
196
187
  - !ruby/object:Gem::Dependency
197
188
  version_requirements: &id012 !ruby/object:Gem::Requirement
198
189
  none: false
199
190
  requirements:
200
- - - "="
191
+ - - ">="
201
192
  - !ruby/object:Gem::Version
202
- hash: 57
193
+ hash: 3
203
194
  segments:
204
- - 2
205
- - 13
206
- - 1
207
- version: 2.13.1
208
- prerelease: false
195
+ - 0
196
+ version: "0"
197
+ name: sequel
209
198
  type: :development
199
+ prerelease: false
210
200
  requirement: *id012
211
- name: rmagick
212
201
  - !ruby/object:Gem::Dependency
213
202
  version_requirements: &id013 !ruby/object:Gem::Requirement
214
203
  none: false
215
204
  requirements:
216
- - - "="
205
+ - - ">="
217
206
  - !ruby/object:Gem::Version
218
- hash: 47
207
+ hash: 3
219
208
  segments:
220
- - 3
221
- - 8
222
- - 4
223
- version: 3.8.4
224
- prerelease: false
209
+ - 0
210
+ version: "0"
211
+ name: rmagick
225
212
  type: :development
213
+ prerelease: false
226
214
  requirement: *id013
227
- name: RubyInline
228
215
  - !ruby/object:Gem::Dependency
229
216
  version_requirements: &id014 !ruby/object:Gem::Requirement
230
217
  none: false
231
218
  requirements:
232
- - - "="
219
+ - - ">="
233
220
  - !ruby/object:Gem::Version
234
- hash: 29
221
+ hash: 3
235
222
  segments:
236
- - 1
237
- - 2
238
- - 1
239
- version: 1.2.1
240
- prerelease: false
223
+ - 0
224
+ version: "0"
225
+ name: RubyInline
241
226
  type: :development
227
+ prerelease: false
242
228
  requirement: *id014
243
- name: image_science
244
229
  - !ruby/object:Gem::Dependency
245
230
  version_requirements: &id015 !ruby/object:Gem::Requirement
246
231
  none: false
247
232
  requirements:
248
- - - "="
233
+ - - ">="
249
234
  - !ruby/object:Gem::Version
250
- hash: 5
235
+ hash: 3
251
236
  segments:
252
- - 2
253
- - 3
254
- version: "2.3"
255
- prerelease: false
237
+ - 0
238
+ version: "0"
239
+ name: image_science
256
240
  type: :development
241
+ prerelease: false
257
242
  requirement: *id015
258
- name: mini_magick
259
243
  - !ruby/object:Gem::Dependency
260
244
  version_requirements: &id016 !ruby/object:Gem::Requirement
261
245
  none: false
262
246
  requirements:
263
- - - "="
247
+ - - ">="
264
248
  - !ruby/object:Gem::Version
265
- hash: 23
249
+ hash: 3
266
250
  segments:
267
- - 1
268
- - 2
269
- - 4
270
- version: 1.2.4
271
- prerelease: false
251
+ - 0
252
+ version: "0"
253
+ name: mini_magick
272
254
  type: :development
255
+ prerelease: false
273
256
  requirement: *id016
274
- name: bson_ext
275
257
  - !ruby/object:Gem::Dependency
276
258
  version_requirements: &id017 !ruby/object:Gem::Requirement
277
259
  none: false
278
260
  requirements:
279
- - - "="
261
+ - - ">="
280
262
  - !ruby/object:Gem::Version
281
- hash: 62196421
263
+ hash: 3
282
264
  segments:
283
- - 2
284
265
  - 0
285
- - 0
286
- - beta
287
- - 19
288
- version: 2.0.0.beta.19
289
- prerelease: false
266
+ version: "0"
267
+ name: bson_ext
290
268
  type: :development
269
+ prerelease: false
291
270
  requirement: *id017
292
- name: mongoid
293
271
  - !ruby/object:Gem::Dependency
294
272
  version_requirements: &id018 !ruby/object:Gem::Requirement
295
273
  none: false
296
274
  requirements:
297
- - - "="
275
+ - - ">="
298
276
  - !ruby/object:Gem::Version
299
- hash: 25
277
+ hash: 3
300
278
  segments:
301
279
  - 0
302
- - 3
303
- - 5
304
- version: 0.3.5
305
- prerelease: false
280
+ version: "0"
281
+ name: mongoid
306
282
  type: :development
283
+ prerelease: false
307
284
  requirement: *id018
308
- name: timecop
309
285
  - !ruby/object:Gem::Dependency
310
286
  version_requirements: &id019 !ruby/object:Gem::Requirement
311
287
  none: false
312
288
  requirements:
313
- - - "="
289
+ - - ">="
314
290
  - !ruby/object:Gem::Version
315
- hash: 1
291
+ hash: 3
316
292
  segments:
317
- - 1
318
- - 5
319
- - 1
320
- version: 1.5.1
321
- prerelease: false
293
+ - 0
294
+ version: "0"
295
+ name: timecop
322
296
  type: :development
297
+ prerelease: false
323
298
  requirement: *id019
324
- name: json
325
299
  - !ruby/object:Gem::Dependency
326
300
  version_requirements: &id020 !ruby/object:Gem::Requirement
327
301
  none: false
328
302
  requirements:
329
- - - "="
303
+ - - ">="
330
304
  - !ruby/object:Gem::Version
331
- hash: 31
305
+ hash: 3
332
306
  segments:
333
- - 1
334
- - 4
335
- - 12
336
- version: 1.4.12
337
- prerelease: false
307
+ - 0
308
+ version: "0"
309
+ name: json
338
310
  type: :development
311
+ prerelease: false
339
312
  requirement: *id020
340
- name: cloudfiles
341
313
  - !ruby/object:Gem::Dependency
342
314
  version_requirements: &id021 !ruby/object:Gem::Requirement
343
315
  none: false
344
316
  requirements:
345
- - - "="
317
+ - - ">="
346
318
  - !ruby/object:Gem::Version
347
- hash: 29
319
+ hash: 3
348
320
  segments:
349
- - 1
350
- - 3
351
- - 3
352
- version: 1.3.3
353
- prerelease: false
321
+ - 0
322
+ version: "0"
323
+ name: cloudfiles
354
324
  type: :development
325
+ prerelease: false
355
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"
356
337
  name: sham_rack
338
+ type: :development
339
+ prerelease: false
340
+ requirement: *id022
357
341
  description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
358
342
  email:
359
343
  - jonas.nicklas@gmail.com
@@ -434,7 +418,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
434
418
  requirements: []
435
419
 
436
420
  rubyforge_project: carrierwave
437
- rubygems_version: 1.5.0
421
+ rubygems_version: 1.4.2
438
422
  signing_key:
439
423
  specification_version: 3
440
424
  summary: Ruby file upload library