carrierwave 0.3.0 → 0.3.1
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 +82 -29
- data/Rakefile +15 -6
- data/lib/carrierwave/compatibility/paperclip.rb +28 -26
- data/lib/carrierwave/mount.rb +7 -1
- data/lib/carrierwave/orm/activerecord.rb +3 -11
- data/lib/carrierwave/orm/datamapper.rb +3 -11
- data/lib/carrierwave/orm/sequel.rb +4 -12
- data/lib/carrierwave/storage/abstract.rb +2 -2
- data/lib/carrierwave/storage/s3.rb +13 -1
- data/lib/carrierwave/uploader/callbacks.rb +6 -6
- data/spec/mount_spec.rb +8 -0
- data/spec/orm/activerecord_spec.rb +10 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
= CarrierWave
|
2
2
|
|
3
|
-
This plugin for Merb and Rails provides a simple and extremely flexible way to
|
3
|
+
This plugin for Merb and Rails provides a simple and extremely flexible way to
|
4
|
+
upload files.
|
5
|
+
|
6
|
+
* RDoc Documentation {available at Rubyforge}[http://carrierwave.rubyforge.org/].
|
7
|
+
* Source code {hosted at GitHub}[http://github.com/jnicklas/carrierwave]
|
8
|
+
* Please {report any issues}[http://github.com/jnicklas/carrierwave/issues] on GitHub
|
4
9
|
|
5
10
|
== Getting Started
|
6
11
|
|
@@ -34,7 +39,8 @@ this should give you a file in:
|
|
34
39
|
|
35
40
|
app/uploaders/avatar_uploader.rb
|
36
41
|
|
37
|
-
Check out this file for some hints on how you can customize your uploader. It
|
42
|
+
Check out this file for some hints on how you can customize your uploader. It
|
43
|
+
should look something like this:
|
38
44
|
|
39
45
|
class AvatarUploader < CarrierWave::Uploader::Base
|
40
46
|
storage :file
|
@@ -48,20 +54,23 @@ You can use your uploader class to store and retrieve files like this:
|
|
48
54
|
|
49
55
|
uploader.retrieve_from_store!('my_file.png')
|
50
56
|
|
51
|
-
CarrierWave gives you a +store+ for permanent storage, and a +cache+ for
|
57
|
+
CarrierWave gives you a +store+ for permanent storage, and a +cache+ for
|
58
|
+
temporary storage. You can use different stores, at the moment a filesystem
|
59
|
+
store and an Amazon S3 store are bundled.
|
52
60
|
|
53
|
-
Most of the time you are going to want to use CarrierWave together with an ORM.
|
61
|
+
Most of the time you are going to want to use CarrierWave together with an ORM.
|
62
|
+
It is quite simple to mount uploaders on columns in your model, so you can
|
63
|
+
simply assign files and get going:
|
54
64
|
|
55
65
|
=== ActiveRecord, DataMapper, Sequel
|
56
66
|
|
57
|
-
|
67
|
+
If you are *not* using Merb or Rails you'll need to require the relevant ORM
|
68
|
+
extension.
|
58
69
|
|
59
70
|
require 'carrierwave/orm/activerecord'
|
60
71
|
require 'carrierwave/orm/datamapper'
|
61
72
|
require 'carrierwave/orm/sequel'
|
62
73
|
|
63
|
-
You don't need to do this if you are using Merb or Rails.
|
64
|
-
|
65
74
|
Open your model file, for ActiveRecord do something like:
|
66
75
|
|
67
76
|
class User < ActiveRecord::Base
|
@@ -82,7 +91,8 @@ Or for Sequel
|
|
82
91
|
mount_uploader :avatar, AvatarUploader
|
83
92
|
end
|
84
93
|
|
85
|
-
Now you can cache files by assigning them to the attribute, they will
|
94
|
+
Now you can cache files by assigning them to the attribute, they will
|
95
|
+
automatically be stored when the record is saved.
|
86
96
|
|
87
97
|
u = User.new
|
88
98
|
u.avatar = params[:file]
|
@@ -93,7 +103,8 @@ Now you can cache files by assigning them to the attribute, they will automatica
|
|
93
103
|
|
94
104
|
== Changing the storage directory
|
95
105
|
|
96
|
-
In order to change where uploaded files are put, just override the +store_dir+
|
106
|
+
In order to change where uploaded files are put, just override the +store_dir+
|
107
|
+
method:
|
97
108
|
|
98
109
|
class MyUploader < CarrierWave::Uploader::Base
|
99
110
|
def store_dir
|
@@ -105,7 +116,8 @@ This works for the file storage as well as Amazon S3.
|
|
105
116
|
|
106
117
|
== Adding versions
|
107
118
|
|
108
|
-
Often you'll want to add different versions of the same file. The classic
|
119
|
+
Often you'll want to add different versions of the same file. The classic
|
120
|
+
example is image thumbnails. There is built in support for this:
|
109
121
|
|
110
122
|
class MyUploader < CarrierWave::Uploader::Base
|
111
123
|
include CarrierWave::RMagick
|
@@ -118,7 +130,9 @@ Often you'll want to add different versions of the same file. The classic exampl
|
|
118
130
|
|
119
131
|
end
|
120
132
|
|
121
|
-
When this uploader is used, an uploaded image would be scaled to be no larger
|
133
|
+
When this uploader is used, an uploaded image would be scaled to be no larger
|
134
|
+
than 800 by 800 pixels. A version called thumb is then created, which is scaled
|
135
|
+
and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
|
122
136
|
|
123
137
|
uploader = AvatarUploader.new
|
124
138
|
uploader.store!(my_file) # size: 1024x768
|
@@ -126,7 +140,8 @@ When this uploader is used, an uploaded image would be scaled to be no larger th
|
|
126
140
|
uploader.url # => '/url/to/my_file.png' # size: 800x600
|
127
141
|
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
|
128
142
|
|
129
|
-
One important thing to remember is that process is called *before* versions are
|
143
|
+
One important thing to remember is that process is called *before* versions are
|
144
|
+
created. This can cut down on processing cost.
|
130
145
|
|
131
146
|
It is possible to nest versions within versions:
|
132
147
|
|
@@ -141,10 +156,11 @@ It is possible to nest versions within versions:
|
|
141
156
|
|
142
157
|
== Making uploads work across form redisplays
|
143
158
|
|
144
|
-
Often you'll notice that uploaded files disappear when a validation
|
145
|
-
|
146
|
-
|
147
|
-
In Rails, this would look
|
159
|
+
Often you'll notice that uploaded files disappear when a validation fails.
|
160
|
+
CarrierWave has a feature that makes it easy to remember the uploaded file even
|
161
|
+
in that case. Suppose your +user+ model has an uploader mounted on +avatar+
|
162
|
+
file, just add a hidden field called +avatar_cache+. In Rails, this would look
|
163
|
+
like this:
|
148
164
|
|
149
165
|
<% form_for @user do |f| %>
|
150
166
|
<p>
|
@@ -154,8 +170,8 @@ In Rails, this would look like this:
|
|
154
170
|
</p>
|
155
171
|
<% end %>
|
156
172
|
|
157
|
-
It might be a good idea to show th user that a file has been uploaded,
|
158
|
-
|
173
|
+
It might be a good idea to show th user that a file has been uploaded, in the
|
174
|
+
case of images, a small thumbnail would be a good indicator:
|
159
175
|
|
160
176
|
<% form_for @user do |f| %>
|
161
177
|
<p>
|
@@ -166,11 +182,17 @@ in the case of images, a small thumbnail would be a good indicator:
|
|
166
182
|
</p>
|
167
183
|
<% end %>
|
168
184
|
|
169
|
-
NOTE: this feature currently requires write access to your filesystem. If write
|
185
|
+
NOTE: this feature currently requires write access to your filesystem. If write
|
186
|
+
access is unavailable you will not be able to upload files. You can prevent
|
187
|
+
CarrierWave from writing to the file system by setting
|
188
|
+
`CarrierWave.config[:cache_to_cache_dir] = false`. This will however break
|
189
|
+
redisplays of forms.
|
170
190
|
|
171
191
|
== Providing a default path
|
172
192
|
|
173
|
-
In many cases, especially when working with images, it might be a good idea to
|
193
|
+
In many cases, especially when working with images, it might be a good idea to
|
194
|
+
provide a default path, a fallback in case no file has been uploaded. You can do
|
195
|
+
this easily by overriding the +default_path+ method in your uploader:
|
174
196
|
|
175
197
|
class MyUploader < CarrierWave::Uploader::Base
|
176
198
|
def default_path
|
@@ -194,17 +216,24 @@ And then in your uploader, set the storage to :s3
|
|
194
216
|
storage :s3
|
195
217
|
end
|
196
218
|
|
197
|
-
That's it! You can still use the +CarrierWave::Uploader#url+ method to return
|
219
|
+
That's it! You can still use the +CarrierWave::Uploader#url+ method to return
|
220
|
+
the url to the file on Amazon S3
|
198
221
|
|
199
222
|
== Using RMagick
|
200
223
|
|
201
|
-
If you're uploading images, you'll probably want to manipulate them in some way,
|
224
|
+
If you're uploading images, you'll probably want to manipulate them in some way,
|
225
|
+
you might want to create thumbnail images for example. CarrierWave comes with a
|
226
|
+
small library to make manipulating images with RMagick easier, you'll need to
|
227
|
+
include it in your Uploader:
|
202
228
|
|
203
229
|
class AvatarUploader < CarrierWave::Uploader::Base
|
204
230
|
include CarrierWave::RMagick
|
205
231
|
end
|
206
232
|
|
207
|
-
The RMagick module gives you a few methods, like
|
233
|
+
The RMagick module gives you a few methods, like
|
234
|
+
+CarrierWave::RMagick#crop_resized+ which manipulate the image file in some way.
|
235
|
+
You can set a +process+ callback, which will call that method any time a file is
|
236
|
+
uploaded.
|
208
237
|
|
209
238
|
class AvatarUploader < CarrierWave::Uploader::Base
|
210
239
|
include CarrierWave::RMagick
|
@@ -217,7 +246,8 @@ The RMagick module gives you a few methods, like +CarrierWave::RMagick#crop_resi
|
|
217
246
|
end
|
218
247
|
end
|
219
248
|
|
220
|
-
Check out the manipulate! method, which makes it easy for you to write your own
|
249
|
+
Check out the manipulate! method, which makes it easy for you to write your own
|
250
|
+
manipulation methods.
|
221
251
|
|
222
252
|
== Using ImageScience
|
223
253
|
|
@@ -237,18 +267,41 @@ If you are using Paperclip, you can use the provided compatibility module:
|
|
237
267
|
include CarrierWave::Compatibility::Paperclip
|
238
268
|
end
|
239
269
|
|
240
|
-
See the documentation for +Paperclip::Compatibility::Paperclip+ for more
|
270
|
+
See the documentation for +Paperclip::Compatibility::Paperclip+ for more
|
271
|
+
detaills.
|
241
272
|
|
242
273
|
Be sure to use mount_on to specify the correct column:
|
243
274
|
|
244
275
|
mount_uploader :avatar, AvatarUploader, :mount_on => :avatar_file_name
|
245
276
|
|
246
|
-
Unfortunately AttachmentFoo differs too much in philosophy for there to be a
|
277
|
+
Unfortunately AttachmentFoo differs too much in philosophy for there to be a
|
278
|
+
sensible compatibility mode. Patches for migrating from other solutions will be
|
279
|
+
happily accepted.
|
280
|
+
|
281
|
+
== i18n
|
282
|
+
|
283
|
+
The activerecord validations use the Rails i18n framework. Add these keys to
|
284
|
+
your translations file:
|
285
|
+
|
286
|
+
carrierwave:
|
287
|
+
errors:
|
288
|
+
integrity: 'Not an image.'
|
289
|
+
processing: 'Cannot resize image.'
|
290
|
+
|
291
|
+
== Contributors
|
292
|
+
|
293
|
+
These people have contributed their time and effort to CarrierWave:
|
294
|
+
|
295
|
+
* Jonas Nicklas
|
296
|
+
* Pavel Kunc
|
247
297
|
|
248
|
-
==
|
298
|
+
== License
|
249
299
|
|
250
|
-
|
300
|
+
MIT-License, see the separate LICENSE file in the source distribution.
|
251
301
|
|
252
302
|
== Read the source
|
253
303
|
|
254
|
-
CarrierWave is still young, but most of it is pretty well documented. It is also
|
304
|
+
CarrierWave is still young, but most of it is pretty well documented. It is also
|
305
|
+
extensively specced, and there are cucumber features for some common use cases.
|
306
|
+
Just dig in and look at the source for more in-depth explanation of what things
|
307
|
+
are doing.
|
data/Rakefile
CHANGED
@@ -3,13 +3,17 @@ require 'rake/gempackagetask'
|
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
gem 'rdoc', '>=2.4.0'
|
5
5
|
require 'rdoc'
|
6
|
-
|
6
|
+
begin
|
7
|
+
require 'sdoc'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
7
10
|
|
8
11
|
require 'spec/rake/spectask'
|
12
|
+
require 'spec/rake/verify_rcov'
|
9
13
|
require 'cucumber/rake/task'
|
10
14
|
|
11
15
|
NAME = "carrierwave"
|
12
|
-
GEM_VERSION = "0.3.
|
16
|
+
GEM_VERSION = "0.3.1"
|
13
17
|
AUTHOR = "Jonas Nicklas"
|
14
18
|
EMAIL = "jonas.nicklas@gmail.com"
|
15
19
|
HOMEPAGE = "http://www.example.com"
|
@@ -82,13 +86,18 @@ Spec::Rake::SpecTask.new('spec') do |t|
|
|
82
86
|
t.spec_files = file_list
|
83
87
|
end
|
84
88
|
|
89
|
+
RCov::VerifyTask.new(:verify_coverage => "spec:rcov") do |t|
|
90
|
+
t.threshold = 95.64
|
91
|
+
t.index_html = 'doc/coverage/index.html'
|
92
|
+
end
|
93
|
+
|
85
94
|
namespace :spec do
|
86
95
|
desc "Run all examples with RCov"
|
87
96
|
Spec::Rake::SpecTask.new('rcov') do |t|
|
88
97
|
t.spec_files = file_list
|
89
98
|
t.rcov = true
|
90
99
|
t.rcov_dir = "doc/coverage"
|
91
|
-
t.rcov_opts = ['--exclude', 'spec']
|
100
|
+
t.rcov_opts = ['--exclude', 'spec,features,lib/generators,gems/*']
|
92
101
|
end
|
93
102
|
|
94
103
|
desc "Generate an html report"
|
@@ -100,7 +109,7 @@ namespace :spec do
|
|
100
109
|
|
101
110
|
end
|
102
111
|
|
103
|
-
desc 'Default: run unit tests.'
|
104
|
-
task :default => 'spec'
|
105
|
-
|
106
112
|
task :superspec => [:spec, :features]
|
113
|
+
|
114
|
+
desc 'Default: run unit tests and features.'
|
115
|
+
task :default => 'superspec'
|
@@ -1,29 +1,3 @@
|
|
1
|
-
# This file contains code taken from Paperclip
|
2
|
-
#
|
3
|
-
# LICENSE
|
4
|
-
#
|
5
|
-
# The MIT License
|
6
|
-
#
|
7
|
-
# Copyright (c) 2008 Jon Yurek and thoughtbot, inc.
|
8
|
-
#
|
9
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
-
# of this software and associated documentation files (the "Software"), to deal
|
11
|
-
# in the Software without restriction, including without limitation the rights
|
12
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
-
# copies of the Software, and to permit persons to whom the Software is
|
14
|
-
# furnished to do so, subject to the following conditions:
|
15
|
-
#
|
16
|
-
# The above copyright notice and this permission notice shall be included in
|
17
|
-
# all copies or substantial portions of the Software.
|
18
|
-
#
|
19
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
-
# THE SOFTWARE.
|
26
|
-
|
27
1
|
module CarrierWave
|
28
2
|
module Compatibility
|
29
3
|
|
@@ -41,6 +15,34 @@ module CarrierWave
|
|
41
15
|
# end
|
42
16
|
# end
|
43
17
|
#
|
18
|
+
# ---
|
19
|
+
#
|
20
|
+
# This file contains code taken from Paperclip
|
21
|
+
#
|
22
|
+
# LICENSE
|
23
|
+
#
|
24
|
+
# The MIT License
|
25
|
+
#
|
26
|
+
# Copyright (c) 2008 Jon Yurek and thoughtbot, inc.
|
27
|
+
#
|
28
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
29
|
+
# of this software and associated documentation files (the "Software"), to deal
|
30
|
+
# in the Software without restriction, including without limitation the rights
|
31
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
32
|
+
# copies of the Software, and to permit persons to whom the Software is
|
33
|
+
# furnished to do so, subject to the following conditions:
|
34
|
+
#
|
35
|
+
# The above copyright notice and this permission notice shall be included in
|
36
|
+
# all copies or substantial portions of the Software.
|
37
|
+
#
|
38
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
39
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
40
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
41
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
42
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
43
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
44
|
+
# THE SOFTWARE.
|
45
|
+
#
|
44
46
|
module Paperclip
|
45
47
|
|
46
48
|
def store_path(for_file=filename)
|
data/lib/carrierwave/mount.rb
CHANGED
@@ -19,6 +19,9 @@ module CarrierWave
|
|
19
19
|
#
|
20
20
|
def uploaders
|
21
21
|
@uploaders ||= {}
|
22
|
+
@uploaders = superclass.uploaders.merge(@uploaders)
|
23
|
+
rescue NoMethodError
|
24
|
+
@uploaders
|
22
25
|
end
|
23
26
|
|
24
27
|
##
|
@@ -28,6 +31,9 @@ module CarrierWave
|
|
28
31
|
#
|
29
32
|
def uploader_options
|
30
33
|
@uploader_options ||= {}
|
34
|
+
@uploader_options = superclass.uploader_options.merge(@uploader_options)
|
35
|
+
rescue NoMethodError
|
36
|
+
@uploader_options
|
31
37
|
end
|
32
38
|
|
33
39
|
##
|
@@ -247,7 +253,7 @@ module CarrierWave
|
|
247
253
|
def write_identifier
|
248
254
|
if remove?
|
249
255
|
record.write_uploader(serialization_column, '')
|
250
|
-
|
256
|
+
elsif not uploader.identifier.blank?
|
251
257
|
record.write_uploader(serialization_column, uploader.identifier)
|
252
258
|
end
|
253
259
|
end
|
@@ -17,17 +17,9 @@ module CarrierWave
|
|
17
17
|
validates_integrity_of column if uploader_options[column.to_sym][:validate_integrity]
|
18
18
|
validates_processing_of column if uploader_options[column.to_sym][:validate_processing]
|
19
19
|
|
20
|
-
after_save
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
before_save do |record|
|
25
|
-
record.send("write_#{column}_identifier")
|
26
|
-
end
|
27
|
-
|
28
|
-
after_destroy do |record|
|
29
|
-
record.send("remove_#{column}!")
|
30
|
-
end
|
20
|
+
after_save "store_#{column}!"
|
21
|
+
before_save "write_#{column}_identifier"
|
22
|
+
after_destroy "remove_#{column}!"
|
31
23
|
end
|
32
24
|
|
33
25
|
##
|
@@ -14,17 +14,9 @@ module CarrierWave
|
|
14
14
|
alias_method :read_uploader, :attribute_get
|
15
15
|
alias_method :write_uploader, :attribute_set
|
16
16
|
|
17
|
-
after :save
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
before :save do
|
22
|
-
send("write_#{column}_identifier")
|
23
|
-
end
|
24
|
-
|
25
|
-
after :destroy do
|
26
|
-
send("remove_#{column}!")
|
27
|
-
end
|
17
|
+
after :save, "store_#{column}!".to_sym
|
18
|
+
before :save, "write_#{column}_identifier".to_sym
|
19
|
+
after :destroy, "remove_#{column}!".to_sym
|
28
20
|
end
|
29
21
|
|
30
22
|
end # DataMapper
|
@@ -11,17 +11,9 @@ module CarrierWave
|
|
11
11
|
alias_method :read_uploader, :[]
|
12
12
|
alias_method :write_uploader, :[]=
|
13
13
|
|
14
|
-
after_save
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
before_save do
|
19
|
-
send("write_#{column}_identifier")
|
20
|
-
end
|
21
|
-
|
22
|
-
before_destroy do
|
23
|
-
send("remove_#{column}!")
|
24
|
-
end
|
14
|
+
after_save "store_#{column}!"
|
15
|
+
before_save "write_#{column}_identifier"
|
16
|
+
before_destroy "remove_#{column}!"
|
25
17
|
end
|
26
18
|
|
27
19
|
# Determine if we're using Sequel > 2.12
|
@@ -29,7 +21,7 @@ module CarrierWave
|
|
29
21
|
# ==== Returns
|
30
22
|
# Bool:: True if Sequel 2.12 or higher False otherwise
|
31
23
|
def self.new_sequel?
|
32
|
-
|
24
|
+
::Sequel::Model.respond_to?(:plugin)
|
33
25
|
end
|
34
26
|
|
35
27
|
end # Sequel
|
@@ -87,8 +87,20 @@ module CarrierWave
|
|
87
87
|
["http://s3.amazonaws.com", bucket, @path].compact.join('/')
|
88
88
|
end
|
89
89
|
|
90
|
+
def respond_to?(*args)
|
91
|
+
super || s3_object.respond_to?(*args)
|
92
|
+
end
|
93
|
+
|
90
94
|
private
|
91
95
|
|
96
|
+
def method_missing(*args, &block)
|
97
|
+
s3_object.send(*args, &block)
|
98
|
+
end
|
99
|
+
|
100
|
+
def s3_object
|
101
|
+
@s3_object ||= AWS::S3::S3Object.find(@path, bucket)
|
102
|
+
end
|
103
|
+
|
92
104
|
def bucket
|
93
105
|
CarrierWave::Storage::S3.bucket
|
94
106
|
end
|
@@ -141,7 +153,7 @@ module CarrierWave
|
|
141
153
|
#
|
142
154
|
def store!(file)
|
143
155
|
AWS::S3::S3Object.store(::File.join(uploader.store_path), file.read, self.class.bucket, :access => self.class.access)
|
144
|
-
CarrierWave::Storage::S3::File.new(uploader.
|
156
|
+
CarrierWave::Storage::S3::File.new(uploader.store_path, uploader.filename)
|
145
157
|
end
|
146
158
|
|
147
159
|
# Do something to retrieve the file
|
@@ -7,31 +7,31 @@ module CarrierWave
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def with_callbacks(kind, *args)
|
10
|
-
self.class.
|
10
|
+
self.class._before_callbacks_for(kind).each { |callback| self.send(callback, *args) }
|
11
11
|
yield
|
12
|
-
self.class.
|
12
|
+
self.class._after_callbacks_for(kind).each { |callback| self.send(callback, *args) }
|
13
13
|
end
|
14
14
|
|
15
15
|
module ClassMethods
|
16
16
|
|
17
|
-
def
|
17
|
+
def _before_callbacks_for(kind) #:nodoc:
|
18
18
|
self._before_callbacks ||= {}
|
19
19
|
self._before_callbacks[kind] ||= []
|
20
20
|
self._before_callbacks[kind]
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
23
|
+
def _after_callbacks_for(kind) #:nodoc:
|
24
24
|
self._after_callbacks ||= {}
|
25
25
|
self._after_callbacks[kind] ||= []
|
26
26
|
self._after_callbacks[kind]
|
27
27
|
end
|
28
28
|
|
29
29
|
def before(kind, callback)
|
30
|
-
|
30
|
+
_before_callbacks_for(kind) << callback
|
31
31
|
end
|
32
32
|
|
33
33
|
def after(kind, callback)
|
34
|
-
|
34
|
+
_after_callbacks_for(kind) << callback
|
35
35
|
end
|
36
36
|
end # ClassMethods
|
37
37
|
|
data/spec/mount_spec.rb
CHANGED
@@ -34,6 +34,14 @@ describe CarrierWave::Mount do
|
|
34
34
|
@instance.image.should be_an_instance_of(@uploader)
|
35
35
|
end
|
36
36
|
|
37
|
+
it "should inherit uploaders to subclasses" do
|
38
|
+
@subclass = Class.new(@class)
|
39
|
+
@subclass_instance = @subclass.new
|
40
|
+
@subclass_instance.image_uploader.should be_an_instance_of(@uploader)
|
41
|
+
@subclass_instance.image = stub_file('test.jpg')
|
42
|
+
@subclass_instance.image.should be_an_instance_of(@uploader)
|
43
|
+
end
|
44
|
+
|
37
45
|
describe '#image_uploader' do
|
38
46
|
it "should return the uploader" do
|
39
47
|
@instance.image_uploader.should be_an_instance_of(@uploader)
|
@@ -16,6 +16,7 @@ class TestMigration < ActiveRecord::Migration
|
|
16
16
|
create_table :events, :force => true do |t|
|
17
17
|
t.column :image, :string
|
18
18
|
t.column :textfile, :string
|
19
|
+
t.column :foo, :string
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -156,6 +157,15 @@ describe CarrierWave::ActiveRecord do
|
|
156
157
|
@event[:image].should == 'test.jpeg'
|
157
158
|
end
|
158
159
|
|
160
|
+
it "should preserve the image when nothing is assigned" do
|
161
|
+
@event.image = stub_file('test.jpeg')
|
162
|
+
@event.save.should be_true
|
163
|
+
@event = @class.find(@event.id)
|
164
|
+
@event.foo = "bar"
|
165
|
+
@event.save.should be_true
|
166
|
+
@event[:image].should == 'test.jpeg'
|
167
|
+
end
|
168
|
+
|
159
169
|
it "should remove the image if remove_image? returns true" do
|
160
170
|
@event.image = stub_file('test.jpeg')
|
161
171
|
@event.save!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-01 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|