carrierwave 0.5.7 → 0.5.8
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.md +76 -14
- data/lib/carrierwave.rb +9 -2
- data/lib/carrierwave/locale/en.yml +5 -1
- data/lib/carrierwave/processing/mime_types.rb +1 -1
- data/lib/carrierwave/processing/mini_magick.rb +6 -7
- data/lib/carrierwave/processing/rmagick.rb +1 -1
- data/lib/carrierwave/sanitized_file.rb +13 -0
- data/lib/carrierwave/storage/file.rb +10 -1
- data/lib/carrierwave/storage/fog.rb +2 -1
- data/lib/carrierwave/storage/s3.rb +1 -1
- data/lib/carrierwave/test/matchers.rb +77 -0
- data/lib/carrierwave/uploader/cache.rb +10 -1
- data/lib/carrierwave/uploader/configuration.rb +6 -0
- data/lib/carrierwave/uploader/extension_whitelist.rb +1 -1
- data/lib/carrierwave/uploader/store.rb +3 -1
- data/lib/carrierwave/uploader/url.rb +3 -1
- data/lib/carrierwave/validations/active_model.rb +7 -22
- data/lib/carrierwave/version.rb +1 -1
- data/lib/generators/templates/uploader.rb +1 -2
- metadata +41 -41
data/README.md
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
This gem provides a simple and extremely flexible way to upload files from Ruby applications.
|
4
4
|
It works well with Rack based web applications, such as Ruby on Rails.
|
5
5
|
|
6
|
+
[![Build Status](https://secure.travis-ci.org/jnicklas/carrierwave.png)](http://travis-ci.org/jnicklas/carrierwave)
|
7
|
+
|
6
8
|
## Information
|
7
9
|
|
8
10
|
* RDoc documentation [available on RubyDoc.info](http://rubydoc.info/gems/carrierwave/frames)
|
@@ -84,7 +86,7 @@ add_column :users, :avatar, :string
|
|
84
86
|
Open your model file and mount the uploader:
|
85
87
|
|
86
88
|
``` ruby
|
87
|
-
class User
|
89
|
+
class User < ActiveRecord::Base
|
88
90
|
mount_uploader :avatar, AvatarUploader
|
89
91
|
end
|
90
92
|
```
|
@@ -171,6 +173,23 @@ contain Russian letters:
|
|
171
173
|
Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party
|
172
174
|
plugins or client-side software.
|
173
175
|
|
176
|
+
## Setting the content type
|
177
|
+
|
178
|
+
If you care about the content type of your files and notice that it's not being set
|
179
|
+
as expected, you can configure your uploaders to use `CarrierWave::MimeTypes`.
|
180
|
+
This adds a dependency on the [mime-types](http://rubygems.org/gems/mime-types) gem,
|
181
|
+
but is recommended when using fog, and fog already has a dependency on mime-types.
|
182
|
+
|
183
|
+
``` ruby
|
184
|
+
require 'carrierwave/processing/mime_types'
|
185
|
+
|
186
|
+
class MyUploader < CarrierWave::Uploader::Base
|
187
|
+
include CarrierWave::MimeTypes
|
188
|
+
|
189
|
+
process :set_content_type
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
174
193
|
## Adding versions
|
175
194
|
|
176
195
|
Often you'll want to add different versions of the same file. The classic
|
@@ -217,6 +236,38 @@ class MyUploader < CarrierWave::Uploader::Base
|
|
217
236
|
end
|
218
237
|
```
|
219
238
|
|
239
|
+
### Conditional versions
|
240
|
+
|
241
|
+
Occasionally you want to restrict the creation of versions on certain
|
242
|
+
properties within the model or based on the picture itself.
|
243
|
+
|
244
|
+
``` ruby
|
245
|
+
class MyUploader < CarrierWave::Uploader::Base
|
246
|
+
|
247
|
+
version :human, :if => :is_human?
|
248
|
+
version :monkey, :if => :is_monkey?
|
249
|
+
version :banner, :if => :is_landscape?
|
250
|
+
|
251
|
+
protected
|
252
|
+
|
253
|
+
def is_human? picture
|
254
|
+
model.can_program?(:ruby)
|
255
|
+
end
|
256
|
+
|
257
|
+
def is_monkey? picture
|
258
|
+
model.favorite_food == 'banana'
|
259
|
+
end
|
260
|
+
|
261
|
+
def is_landscape? picture
|
262
|
+
image = MiniMagick::Image.open(picture.path)
|
263
|
+
image[:width] > image[:height]
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
```
|
268
|
+
|
269
|
+
The `model` variable points to the instance object the uploader is attached to.
|
270
|
+
|
220
271
|
## Making uploads work across form redisplays
|
221
272
|
|
222
273
|
Often you'll notice that uploaded files disappear when a validation fails.
|
@@ -470,7 +521,7 @@ This is *highly* recommended, as without it every request requires a lookup
|
|
470
521
|
of this information.
|
471
522
|
|
472
523
|
``` ruby
|
473
|
-
config.fog_host = "c000000.cdn.rackspacecloud.com"
|
524
|
+
config.fog_host = "http://c000000.cdn.rackspacecloud.com"
|
474
525
|
```
|
475
526
|
|
476
527
|
The UK Rackspace Cloud doesn’t have the same auth server as the US Cloud.
|
@@ -558,18 +609,6 @@ end
|
|
558
609
|
Check out the manipulate! method, which makes it easy for you to write your own
|
559
610
|
manipulation methods.
|
560
611
|
|
561
|
-
## Using ImageScience
|
562
|
-
|
563
|
-
ImageScience works the same way as RMagick.
|
564
|
-
|
565
|
-
``` ruby
|
566
|
-
class AvatarUploader < CarrierWave::Uploader::Base
|
567
|
-
include CarrierWave::ImageScience
|
568
|
-
|
569
|
-
process :resize_to_fill => [200, 200]
|
570
|
-
end
|
571
|
-
```
|
572
|
-
|
573
612
|
## Using MiniMagick
|
574
613
|
|
575
614
|
MiniMagick is similar to RMagick but performs all the operations using the 'mogrify'
|
@@ -630,6 +669,29 @@ errors:
|
|
630
669
|
carrierwave_integrity_error: 'Not an image.'
|
631
670
|
```
|
632
671
|
|
672
|
+
## Large files
|
673
|
+
|
674
|
+
By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then
|
675
|
+
copying the file into the store. For large files, this can be prohibitively time consuming.
|
676
|
+
|
677
|
+
You may change this behavior by overriding either or both of the `move_to_cache` and
|
678
|
+
`move_to_store` methods:
|
679
|
+
|
680
|
+
``` ruby
|
681
|
+
class MyUploader < CarrierWave::Uploader::Base
|
682
|
+
def move_to_cache
|
683
|
+
true
|
684
|
+
end
|
685
|
+
def move_to_store
|
686
|
+
true
|
687
|
+
end
|
688
|
+
end
|
689
|
+
```
|
690
|
+
|
691
|
+
When the `move_to_cache` and/or `move_to_store` methods return true, files will be moved (instead of copied) to the cache and store respectively.
|
692
|
+
|
693
|
+
This has only been tested with the local filesystem store.
|
694
|
+
|
633
695
|
## Contributing to CarrierWave
|
634
696
|
|
635
697
|
CarrierWave thrives on a large number of [contributors](https://github.com/jnicklas/carrierwave/contributors),
|
data/lib/carrierwave.rb
CHANGED
@@ -15,7 +15,7 @@ require 'active_support/memoizable'
|
|
15
15
|
module CarrierWave
|
16
16
|
|
17
17
|
class << self
|
18
|
-
attr_accessor :root
|
18
|
+
attr_accessor :root, :base_path
|
19
19
|
|
20
20
|
def configure(&block)
|
21
21
|
CarrierWave::Uploader::Base.configure(&block)
|
@@ -92,6 +92,7 @@ elsif defined?(Rails)
|
|
92
92
|
class Railtie < Rails::Railtie
|
93
93
|
initializer "carrierwave.setup_paths" do
|
94
94
|
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
|
95
|
+
CarrierWave.base_path = ENV['RAILS_RELATIVE_URL_ROOT']
|
95
96
|
end
|
96
97
|
|
97
98
|
initializer "carrierwave.active_record" do
|
@@ -104,6 +105,12 @@ elsif defined?(Rails)
|
|
104
105
|
|
105
106
|
elsif defined?(Sinatra)
|
106
107
|
|
107
|
-
CarrierWave.root = Sinatra::Application.
|
108
|
+
CarrierWave.root = if Sinatra::Application.respond_to?(:public_folder)
|
109
|
+
# Sinatra >= 1.3
|
110
|
+
Sinatra::Application.public_folder
|
111
|
+
else
|
112
|
+
# Sinatra < 1.3
|
113
|
+
Sinatra::Application.public
|
114
|
+
end
|
108
115
|
|
109
116
|
end
|
@@ -2,4 +2,8 @@ en:
|
|
2
2
|
errors:
|
3
3
|
messages:
|
4
4
|
carrierwave_processing_error: failed to be processed
|
5
|
-
carrierwave_integrity_error: is not an allowed file type
|
5
|
+
carrierwave_integrity_error: is not of an allowed file type
|
6
|
+
extension_white_list_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
|
7
|
+
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image? Original Error: %{e}"
|
8
|
+
mime_types_processing_error: "Failed to process file with MIME::Types, maybe not valid content-type? Original Error: %{e}"
|
9
|
+
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
|
@@ -51,7 +51,7 @@ module CarrierWave
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
rescue ::MIME::InvalidContentType => e
|
54
|
-
raise CarrierWave::ProcessingError.
|
54
|
+
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mime_types_processing_error", :e => e)
|
55
55
|
end
|
56
56
|
|
57
57
|
end # MimeTypes
|
@@ -32,16 +32,15 @@ module CarrierWave
|
|
32
32
|
# class MyUploader < CarrierWave::Uploader::Base
|
33
33
|
# include CarrierWave::MiniMagick
|
34
34
|
#
|
35
|
-
# process :
|
35
|
+
# process :radial_blur => 10
|
36
36
|
#
|
37
|
-
# def
|
37
|
+
# def radial_blur(amount)
|
38
38
|
# manipulate! do |img|
|
39
|
-
# img
|
40
|
-
# img = img
|
41
|
-
# img
|
39
|
+
# img.radial_blur(amount)
|
40
|
+
# img = yield(img) if block_given?
|
41
|
+
# img
|
42
42
|
# end
|
43
43
|
# end
|
44
|
-
# end
|
45
44
|
#
|
46
45
|
# === Note
|
47
46
|
#
|
@@ -246,7 +245,7 @@ module CarrierWave
|
|
246
245
|
image.write(current_path)
|
247
246
|
::MiniMagick::Image.open(current_path)
|
248
247
|
rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
|
249
|
-
raise CarrierWave::ProcessingError.
|
248
|
+
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e)
|
250
249
|
end
|
251
250
|
|
252
251
|
end # MiniMagick
|
@@ -266,7 +266,7 @@ module CarrierWave
|
|
266
266
|
end
|
267
267
|
destroy_image(frames)
|
268
268
|
rescue ::Magick::ImageMagickError => e
|
269
|
-
raise CarrierWave::ProcessingError.
|
269
|
+
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e)
|
270
270
|
end
|
271
271
|
|
272
272
|
private
|
@@ -181,6 +181,7 @@ module CarrierWave
|
|
181
181
|
end
|
182
182
|
chmod!(new_path, permissions)
|
183
183
|
self.file = new_path
|
184
|
+
self
|
184
185
|
end
|
185
186
|
|
186
187
|
##
|
@@ -216,6 +217,18 @@ module CarrierWave
|
|
216
217
|
FileUtils.rm(self.path) if exists?
|
217
218
|
end
|
218
219
|
|
220
|
+
##
|
221
|
+
# Returns a File object, or nil if it does not exist.
|
222
|
+
#
|
223
|
+
# === Returns
|
224
|
+
#
|
225
|
+
# [File] a File object representing the SanitizedFile
|
226
|
+
#
|
227
|
+
def to_file
|
228
|
+
return @file if @file.is_a?(File)
|
229
|
+
File.open(path) if exists?
|
230
|
+
end
|
231
|
+
|
219
232
|
##
|
220
233
|
# Returns the content type of the file.
|
221
234
|
#
|
@@ -13,6 +13,11 @@ module CarrierWave
|
|
13
13
|
##
|
14
14
|
# Move the file to the uploader's store path.
|
15
15
|
#
|
16
|
+
# By default, store!() uses copy_to(), which operates by copying the file
|
17
|
+
# from the cache to the store, then deleting the file from the cache.
|
18
|
+
# If move_to_store() is overriden to return true, then store!() uses move_to(),
|
19
|
+
# which simply moves the file from cache to store. Useful for large files.
|
20
|
+
#
|
16
21
|
# === Parameters
|
17
22
|
#
|
18
23
|
# [file (CarrierWave::SanitizedFile)] the file to store
|
@@ -23,7 +28,11 @@ module CarrierWave
|
|
23
28
|
#
|
24
29
|
def store!(file)
|
25
30
|
path = ::File.expand_path(uploader.store_path, uploader.root)
|
26
|
-
|
31
|
+
if uploader.move_to_store
|
32
|
+
file.move_to(path, uploader.permissions)
|
33
|
+
else
|
34
|
+
file.copy_to(path, uploader.permissions)
|
35
|
+
end
|
27
36
|
end
|
28
37
|
|
29
38
|
##
|
@@ -225,9 +225,10 @@ module CarrierWave
|
|
225
225
|
#
|
226
226
|
# [Boolean] true on success or raises error
|
227
227
|
def store(new_file)
|
228
|
+
fog_file = new_file.to_file
|
228
229
|
@content_type ||= new_file.content_type
|
229
230
|
@file = directory.files.create({
|
230
|
-
:body => new_file.read,
|
231
|
+
:body => fog_file ? fog_file : new_file.read,
|
231
232
|
:content_type => @content_type,
|
232
233
|
:key => path,
|
233
234
|
:public => @uploader.fog_public
|
@@ -132,7 +132,7 @@ module CarrierWave
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def authenticated_url
|
135
|
-
connection.
|
135
|
+
connection.get_object_https_url(bucket, path, Time.now + authentication_timeout)
|
136
136
|
end
|
137
137
|
|
138
138
|
def store(file)
|
@@ -13,16 +13,23 @@ module CarrierWave
|
|
13
13
|
def initialize(expected)
|
14
14
|
@expected = expected
|
15
15
|
end
|
16
|
+
|
16
17
|
def matches?(actual)
|
17
18
|
@actual = actual
|
18
19
|
FileUtils.identical?(@actual, @expected)
|
19
20
|
end
|
21
|
+
|
20
22
|
def failure_message
|
21
23
|
"expected #{@actual.inspect} to be identical to #{@expected.inspect}"
|
22
24
|
end
|
25
|
+
|
23
26
|
def negative_failure_message
|
24
27
|
"expected #{@actual.inspect} to not be identical to #{@expected.inspect}"
|
25
28
|
end
|
29
|
+
|
30
|
+
def description
|
31
|
+
"be identical to #{@expected.inspect}"
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
def be_identical_to(expected)
|
@@ -47,6 +54,10 @@ module CarrierWave
|
|
47
54
|
def negative_failure_message
|
48
55
|
"expected #{@actual.inspect} not to have permissions #{@expected.to_s(8)}, but it did"
|
49
56
|
end
|
57
|
+
|
58
|
+
def description
|
59
|
+
"have permissions #{@expected.to_s(8)}"
|
60
|
+
end
|
50
61
|
end
|
51
62
|
|
52
63
|
def have_permissions(expected)
|
@@ -75,6 +86,9 @@ module CarrierWave
|
|
75
86
|
"expected #{@actual.current_path.inspect} to be larger than #{@width} by #{@height}, but it wasn't."
|
76
87
|
end
|
77
88
|
|
89
|
+
def description
|
90
|
+
"be no larger than #{@width} by #{@height}"
|
91
|
+
end
|
78
92
|
end
|
79
93
|
|
80
94
|
def be_no_larger_than(width, height)
|
@@ -103,12 +117,75 @@ module CarrierWave
|
|
103
117
|
"expected #{@actual.current_path.inspect} not to have an exact size of #{@width} by #{@height}, but it did."
|
104
118
|
end
|
105
119
|
|
120
|
+
def description
|
121
|
+
"have an exact size of #{@width} by #{@height}"
|
122
|
+
end
|
106
123
|
end
|
107
124
|
|
108
125
|
def have_dimensions(width, height)
|
109
126
|
HaveDimensions.new(width, height)
|
110
127
|
end
|
111
128
|
|
129
|
+
class BeNoWiderThan # :nodoc:
|
130
|
+
def initialize(width)
|
131
|
+
@width = width
|
132
|
+
end
|
133
|
+
|
134
|
+
def matches?(actual)
|
135
|
+
@actual = actual
|
136
|
+
# Satisfy expectation here. Return false or raise an error if it's not met.
|
137
|
+
image = ImageLoader.load_image(@actual.current_path)
|
138
|
+
@actual_width = image.width
|
139
|
+
@actual_width <= @width
|
140
|
+
end
|
141
|
+
|
142
|
+
def failure_message
|
143
|
+
"expected #{@actual.current_path.inspect} to be no wider than #{@width}, but it was #{@actual_width}."
|
144
|
+
end
|
145
|
+
|
146
|
+
def negative_failure_message
|
147
|
+
"expected #{@actual.current_path.inspect} not to be wider than #{@width}, but it is."
|
148
|
+
end
|
149
|
+
|
150
|
+
def description
|
151
|
+
"have a width less than or equal to #{@width}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def be_no_wider_than(width)
|
156
|
+
BeNoWiderThan.new(width)
|
157
|
+
end
|
158
|
+
|
159
|
+
class BeNoTallerThan # :nodoc:
|
160
|
+
def initialize(height)
|
161
|
+
@height = height
|
162
|
+
end
|
163
|
+
|
164
|
+
def matches?(actual)
|
165
|
+
@actual = actual
|
166
|
+
# Satisfy expectation here. Return false or raise an error if it's not met.
|
167
|
+
image = ImageLoader.load_image(@actual.current_path)
|
168
|
+
@actual_height = image.height
|
169
|
+
@actual_height <= @height
|
170
|
+
end
|
171
|
+
|
172
|
+
def failure_message
|
173
|
+
"expected #{@actual.current_path.inspect} to be no taller than #{@height}, but it was #{@actual_height}."
|
174
|
+
end
|
175
|
+
|
176
|
+
def negative_failure_message
|
177
|
+
"expected #{@actual.current_path.inspect} not to be taller than #{@height}, but it is."
|
178
|
+
end
|
179
|
+
|
180
|
+
def description
|
181
|
+
"have a height less than or equal to #{@height}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def be_no_height_than(height)
|
186
|
+
BeNoTallerThan.new(height)
|
187
|
+
end
|
188
|
+
|
112
189
|
class ImageLoader # :nodoc:
|
113
190
|
def self.load_image(filename)
|
114
191
|
if defined? ::MiniMagick
|
@@ -90,6 +90,11 @@ module CarrierWave
|
|
90
90
|
##
|
91
91
|
# Caches the given file. Calls process! to trigger any process callbacks.
|
92
92
|
#
|
93
|
+
# By default, cache!() uses copy_to(), which operates by copying the file
|
94
|
+
# to the cache, then deleting the original file. If move_to_cache() is
|
95
|
+
# overriden to return true, then cache!() uses move_to(), which simply
|
96
|
+
# moves the file to the cache. Useful for large files.
|
97
|
+
#
|
93
98
|
# === Parameters
|
94
99
|
#
|
95
100
|
# [new_file (File, IOString, Tempfile)] any kind of file object
|
@@ -110,7 +115,11 @@ module CarrierWave
|
|
110
115
|
@filename = new_file.filename
|
111
116
|
self.original_filename = new_file.filename
|
112
117
|
|
113
|
-
|
118
|
+
if move_to_cache
|
119
|
+
@file = new_file.move_to(cache_path, permissions)
|
120
|
+
else
|
121
|
+
@file = new_file.copy_to(cache_path, permissions)
|
122
|
+
end
|
114
123
|
end
|
115
124
|
end
|
116
125
|
end
|
@@ -8,6 +8,7 @@ module CarrierWave
|
|
8
8
|
class_attribute :_storage, :instance_writer => false
|
9
9
|
|
10
10
|
add_config :root
|
11
|
+
add_config :base_path
|
11
12
|
add_config :permissions
|
12
13
|
add_config :storage_engines
|
13
14
|
add_config :s3_access_policy
|
@@ -37,6 +38,8 @@ module CarrierWave
|
|
37
38
|
add_config :enable_processing
|
38
39
|
add_config :ensure_multipart_form
|
39
40
|
add_config :delete_tmp_file_after_storage
|
41
|
+
add_config :move_to_cache
|
42
|
+
add_config :move_to_store
|
40
43
|
add_config :remove_previously_stored_files_after_update
|
41
44
|
|
42
45
|
# fog
|
@@ -144,12 +147,15 @@ module CarrierWave
|
|
144
147
|
config.store_dir = 'uploads'
|
145
148
|
config.cache_dir = 'uploads/tmp'
|
146
149
|
config.delete_tmp_file_after_storage = true
|
150
|
+
config.move_to_cache = false
|
151
|
+
config.move_to_store = false
|
147
152
|
config.remove_previously_stored_files_after_update = true
|
148
153
|
config.ignore_integrity_errors = true
|
149
154
|
config.ignore_processing_errors = true
|
150
155
|
config.validate_integrity = true
|
151
156
|
config.validate_processing = true
|
152
157
|
config.root = CarrierWave.root
|
158
|
+
config.base_path = CarrierWave.base_path
|
153
159
|
config.enable_processing = true
|
154
160
|
config.ensure_multipart_form = true
|
155
161
|
end
|
@@ -40,7 +40,7 @@ module CarrierWave
|
|
40
40
|
def check_whitelist!(new_file)
|
41
41
|
extension = new_file.extension.to_s
|
42
42
|
if extension_white_list and not extension_white_list.detect { |item| extension =~ /\A#{item}\z/i }
|
43
|
-
raise CarrierWave::IntegrityError, "
|
43
|
+
raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_white_list_error", :extension => new_file.extension.inspect, :allowed_types => extension_white_list.inspect)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -57,7 +57,7 @@ module CarrierWave
|
|
57
57
|
if @file and @cache_id
|
58
58
|
with_callbacks(:store, new_file) do
|
59
59
|
new_file = storage.store!(@file)
|
60
|
-
@file.delete if delete_tmp_file_after_storage
|
60
|
+
@file.delete if (delete_tmp_file_after_storage && ! move_to_store)
|
61
61
|
delete_cache_id
|
62
62
|
@file = new_file
|
63
63
|
@cache_id = nil
|
@@ -79,6 +79,8 @@ module CarrierWave
|
|
79
79
|
# Ignore: path is not a dir
|
80
80
|
rescue Errno::ENOTEMPTY, Errno::EEXIST
|
81
81
|
# Ignore: dir is not empty
|
82
|
+
rescue SystemCallError
|
83
|
+
# no such directory on JRuby
|
82
84
|
end
|
83
85
|
end
|
84
86
|
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Uploader
|
5
5
|
module Url
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include CarrierWave::Uploader::Configuration
|
6
8
|
|
7
9
|
##
|
8
10
|
# === Returns
|
@@ -13,7 +15,7 @@ module CarrierWave
|
|
13
15
|
if file.respond_to?(:url) and not file.url.blank?
|
14
16
|
file.url
|
15
17
|
elsif current_path
|
16
|
-
File.expand_path(current_path).gsub(File.expand_path(root), '')
|
18
|
+
(base_path || "") + File.expand_path(current_path).gsub(File.expand_path(root), '')
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
@@ -14,8 +14,9 @@ module CarrierWave
|
|
14
14
|
class ProcessingValidator < ::ActiveModel::EachValidator
|
15
15
|
|
16
16
|
def validate_each(record, attribute, value)
|
17
|
-
if record.send("#{attribute}_processing_error")
|
18
|
-
|
17
|
+
if e = record.send("#{attribute}_processing_error")
|
18
|
+
message = (e.message == e.class.to_s) ? :carrierwave_processing_error : e.message
|
19
|
+
record.errors.add(attribute, message)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
@@ -23,8 +24,9 @@ module CarrierWave
|
|
23
24
|
class IntegrityValidator < ::ActiveModel::EachValidator
|
24
25
|
|
25
26
|
def validate_each(record, attribute, value)
|
26
|
-
if record.send("#{attribute}_integrity_error")
|
27
|
-
|
27
|
+
if e = record.send("#{attribute}_integrity_error")
|
28
|
+
message = (e.message == e.class.to_s) ? :carrierwave_integrity_error : e.message
|
29
|
+
record.errors.add(attribute, message)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -36,14 +38,6 @@ module CarrierWave
|
|
36
38
|
#
|
37
39
|
# Accepts the usual parameters for validations in Rails (:if, :unless, etc...)
|
38
40
|
#
|
39
|
-
# === Note
|
40
|
-
#
|
41
|
-
# Set this key in your translations file for I18n:
|
42
|
-
#
|
43
|
-
# carrierwave:
|
44
|
-
# errors:
|
45
|
-
# integrity: 'Here be an error message'
|
46
|
-
#
|
47
41
|
def validates_integrity_of(*attr_names)
|
48
42
|
validates_with IntegrityValidator, _merge_attributes(attr_names)
|
49
43
|
end
|
@@ -54,14 +48,6 @@ module CarrierWave
|
|
54
48
|
#
|
55
49
|
# Accepts the usual parameters for validations in Rails (:if, :unless, etc...)
|
56
50
|
#
|
57
|
-
# === Note
|
58
|
-
#
|
59
|
-
# Set this key in your translations file for I18n:
|
60
|
-
#
|
61
|
-
# carrierwave:
|
62
|
-
# errors:
|
63
|
-
# processing: 'Here be an error message'
|
64
|
-
#
|
65
51
|
def validates_processing_of(*attr_names)
|
66
52
|
validates_with ProcessingValidator, _merge_attributes(attr_names)
|
67
53
|
end
|
@@ -75,5 +61,4 @@ module CarrierWave
|
|
75
61
|
end
|
76
62
|
end
|
77
63
|
|
78
|
-
I18n.load_path << File.join(File.dirname(__FILE__), "..", "locale", 'en.yml')
|
79
|
-
|
64
|
+
I18n.load_path << File.join(File.dirname(__FILE__), "..", "locale", 'en.yml')
|
data/lib/carrierwave/version.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
class <%= class_name %>Uploader < CarrierWave::Uploader::Base
|
4
4
|
|
5
|
-
# Include RMagick or
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
6
|
# include CarrierWave::RMagick
|
7
7
|
# include CarrierWave::MiniMagick
|
8
|
-
# include CarrierWave::ImageScience
|
9
8
|
|
10
9
|
# Choose what kind of storage to use for this uploader:
|
11
10
|
storage :file
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 8
|
10
|
+
version: 0.5.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonas Nicklas
|
@@ -15,10 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-10 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
+
name: activesupport
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
22
25
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
26
|
none: false
|
24
27
|
requirements:
|
@@ -29,11 +32,11 @@ dependencies:
|
|
29
32
|
- 3
|
30
33
|
- 0
|
31
34
|
version: "3.0"
|
32
|
-
prerelease: false
|
33
|
-
type: :runtime
|
34
35
|
requirement: *id001
|
35
|
-
name: activesupport
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
+
name: rails
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
37
40
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
41
|
none: false
|
39
42
|
requirements:
|
@@ -44,11 +47,11 @@ dependencies:
|
|
44
47
|
- 3
|
45
48
|
- 0
|
46
49
|
version: "3.0"
|
47
|
-
prerelease: false
|
48
|
-
type: :development
|
49
50
|
requirement: *id002
|
50
|
-
name: rails
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
+
name: sqlite3
|
53
|
+
type: :development
|
54
|
+
prerelease: false
|
52
55
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
56
|
none: false
|
54
57
|
requirements:
|
@@ -58,11 +61,11 @@ dependencies:
|
|
58
61
|
segments:
|
59
62
|
- 0
|
60
63
|
version: "0"
|
61
|
-
prerelease: false
|
62
|
-
type: :development
|
63
64
|
requirement: *id003
|
64
|
-
name: sqlite3
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
+
name: cucumber
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
66
69
|
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
70
|
none: false
|
68
71
|
requirements:
|
@@ -72,11 +75,11 @@ dependencies:
|
|
72
75
|
segments:
|
73
76
|
- 0
|
74
77
|
version: "0"
|
75
|
-
prerelease: false
|
76
|
-
type: :development
|
77
78
|
requirement: *id004
|
78
|
-
name: cucumber
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
+
name: json
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
80
83
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
81
84
|
none: false
|
82
85
|
requirements:
|
@@ -86,11 +89,11 @@ dependencies:
|
|
86
89
|
segments:
|
87
90
|
- 0
|
88
91
|
version: "0"
|
89
|
-
prerelease: false
|
90
|
-
type: :development
|
91
92
|
requirement: *id005
|
92
|
-
name: json
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
+
name: rspec
|
95
|
+
type: :development
|
96
|
+
prerelease: false
|
94
97
|
version_requirements: &id006 !ruby/object:Gem::Requirement
|
95
98
|
none: false
|
96
99
|
requirements:
|
@@ -101,11 +104,11 @@ dependencies:
|
|
101
104
|
- 2
|
102
105
|
- 0
|
103
106
|
version: "2.0"
|
104
|
-
prerelease: false
|
105
|
-
type: :development
|
106
107
|
requirement: *id006
|
107
|
-
name: rspec
|
108
108
|
- !ruby/object:Gem::Dependency
|
109
|
+
name: sham_rack
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
109
112
|
version_requirements: &id007 !ruby/object:Gem::Requirement
|
110
113
|
none: false
|
111
114
|
requirements:
|
@@ -115,11 +118,11 @@ dependencies:
|
|
115
118
|
segments:
|
116
119
|
- 0
|
117
120
|
version: "0"
|
118
|
-
prerelease: false
|
119
|
-
type: :development
|
120
121
|
requirement: *id007
|
121
|
-
name: sham_rack
|
122
122
|
- !ruby/object:Gem::Dependency
|
123
|
+
name: timecop
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
123
126
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
124
127
|
none: false
|
125
128
|
requirements:
|
@@ -129,11 +132,11 @@ dependencies:
|
|
129
132
|
segments:
|
130
133
|
- 0
|
131
134
|
version: "0"
|
132
|
-
prerelease: false
|
133
|
-
type: :development
|
134
135
|
requirement: *id008
|
135
|
-
name: timecop
|
136
136
|
- !ruby/object:Gem::Dependency
|
137
|
+
name: cloudfiles
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
137
140
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
138
141
|
none: false
|
139
142
|
requirements:
|
@@ -143,11 +146,11 @@ dependencies:
|
|
143
146
|
segments:
|
144
147
|
- 0
|
145
148
|
version: "0"
|
146
|
-
prerelease: false
|
147
|
-
type: :development
|
148
149
|
requirement: *id009
|
149
|
-
name: cloudfiles
|
150
150
|
- !ruby/object:Gem::Dependency
|
151
|
+
name: fog
|
152
|
+
type: :development
|
153
|
+
prerelease: false
|
151
154
|
version_requirements: &id010 !ruby/object:Gem::Requirement
|
152
155
|
none: false
|
153
156
|
requirements:
|
@@ -157,11 +160,11 @@ dependencies:
|
|
157
160
|
segments:
|
158
161
|
- 0
|
159
162
|
version: "0"
|
160
|
-
prerelease: false
|
161
|
-
type: :development
|
162
163
|
requirement: *id010
|
163
|
-
name: fog
|
164
164
|
- !ruby/object:Gem::Dependency
|
165
|
+
name: mini_magick
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
165
168
|
version_requirements: &id011 !ruby/object:Gem::Requirement
|
166
169
|
none: false
|
167
170
|
requirements:
|
@@ -171,11 +174,11 @@ dependencies:
|
|
171
174
|
segments:
|
172
175
|
- 0
|
173
176
|
version: "0"
|
174
|
-
prerelease: false
|
175
|
-
type: :development
|
176
177
|
requirement: *id011
|
177
|
-
name: mini_magick
|
178
178
|
- !ruby/object:Gem::Dependency
|
179
|
+
name: rmagick
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
179
182
|
version_requirements: &id012 !ruby/object:Gem::Requirement
|
180
183
|
none: false
|
181
184
|
requirements:
|
@@ -185,10 +188,7 @@ dependencies:
|
|
185
188
|
segments:
|
186
189
|
- 0
|
187
190
|
version: "0"
|
188
|
-
prerelease: false
|
189
|
-
type: :development
|
190
191
|
requirement: *id012
|
191
|
-
name: rmagick
|
192
192
|
description: Upload files in your Ruby applications, map them to a range of ORMs, store them on different backends.
|
193
193
|
email:
|
194
194
|
- jonas.nicklas@gmail.com
|
@@ -264,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
264
|
requirements: []
|
265
265
|
|
266
266
|
rubyforge_project: carrierwave
|
267
|
-
rubygems_version: 1.
|
267
|
+
rubygems_version: 1.6.2
|
268
268
|
signing_key:
|
269
269
|
specification_version: 3
|
270
270
|
summary: Ruby file upload library
|