carrierwave 0.4.0 → 0.4.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/History.txt +9 -1
- data/README.rdoc +30 -7
- data/features/support/env.rb +1 -3
- data/lib/carrierwave.rb +13 -29
- data/lib/carrierwave/orm/sequel.rb +4 -16
- data/lib/carrierwave/processing/image_science.rb +54 -25
- data/lib/carrierwave/processing/rmagick.rb +2 -4
- data/lib/carrierwave/test/matchers.rb +22 -8
- data/lib/carrierwave/uploader/configuration.rb +59 -3
- data/lib/carrierwave/uploader/store.rb +0 -40
- data/lib/carrierwave/uploader/versions.rb +2 -0
- data/rails_generators/uploader/templates/uploader.rb +1 -1
- data/spec/orm/sequel_spec.rb +3 -12
- data/spec/spec_helper.rb +1 -3
- data/spec/uploader/configuration_spec.rb +44 -10
- data/spec/uploader/store_spec.rb +0 -31
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
=== Version 0.4.
|
1
|
+
=== Version 0.4.1
|
2
|
+
|
3
|
+
* [changed] Major changes to the ImageScience module, it actually works now!
|
4
|
+
* [fixed] Bug in configuration where it complais that it can't dup Symbol
|
5
|
+
|
6
|
+
* [removed] Support for Sequel < 2.12
|
7
|
+
* [removed] `crop_resized` and `resize` aliases in RMagick, use `resize_to_fill` and `resize_to_fit` respectively
|
8
|
+
|
9
|
+
=== Version 0.4.0 2009-10-12
|
2
10
|
|
3
11
|
* [changed] the `public` option has been renamed `root` and the old `root` option was removed. No more ambiguity.
|
4
12
|
* [changed] Major *breaking* changes to the configuration syntax.
|
data/README.rdoc
CHANGED
@@ -128,7 +128,7 @@ example is image thumbnails. There is built in support for this:
|
|
128
128
|
process :resize => [800, 800]
|
129
129
|
|
130
130
|
version :thumb do
|
131
|
-
process :
|
131
|
+
process :resize_to_fill => [200,200]
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
@@ -271,14 +271,14 @@ include it in your Uploader:
|
|
271
271
|
end
|
272
272
|
|
273
273
|
The RMagick module gives you a few methods, like
|
274
|
-
+CarrierWave::RMagick#
|
275
|
-
You can set a +process+ callback, which will call that method any time a
|
276
|
-
uploaded.
|
274
|
+
+CarrierWave::RMagick#resize_to_fill+ which manipulate the image file in some
|
275
|
+
way. You can set a +process+ callback, which will call that method any time a
|
276
|
+
file is uploaded.
|
277
277
|
|
278
278
|
class AvatarUploader < CarrierWave::Uploader::Base
|
279
279
|
include CarrierWave::RMagick
|
280
280
|
|
281
|
-
process :
|
281
|
+
process :resize_to_fill => [200, 200]
|
282
282
|
process :convert => 'png'
|
283
283
|
|
284
284
|
def filename
|
@@ -296,7 +296,30 @@ ImageScience works the same way as RMagick.
|
|
296
296
|
class AvatarUploader < CarrierWave::Uploader::Base
|
297
297
|
include CarrierWave::ImageScience
|
298
298
|
|
299
|
-
process :
|
299
|
+
process :resize_to_fill => [200, 200]
|
300
|
+
end
|
301
|
+
|
302
|
+
== Using MiniMagick
|
303
|
+
|
304
|
+
MiniMagick is similar to RMagick but performs all the operations using the 'mogrify'
|
305
|
+
command which is part of the standard ImageMagick kit. This allows you to have the power
|
306
|
+
of ImageMagick without having to worry about installing all the RMagick libraries.
|
307
|
+
|
308
|
+
See the MiniMagick site for more details:
|
309
|
+
|
310
|
+
http://github.com/probablycorey/mini_magick
|
311
|
+
|
312
|
+
And the ImageMagick command line options for more for whats on offer:
|
313
|
+
|
314
|
+
http://www.imagemagick.org/script/command-line-options.php
|
315
|
+
|
316
|
+
Currently, the MiniMagick carrierwave processor provides exactly the same methods as
|
317
|
+
for the RMagick processor.
|
318
|
+
|
319
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
320
|
+
include CarrierWave::MiniMagick
|
321
|
+
|
322
|
+
process :resize_to_fill => [200, 200]
|
300
323
|
end
|
301
324
|
|
302
325
|
== Migrating
|
@@ -375,4 +398,4 @@ extensively specced, and there are cucumber features for some common use cases.
|
|
375
398
|
Just dig in and look at the source for more in-depth explanation of what things
|
376
399
|
are doing.
|
377
400
|
|
378
|
-
Issues are reported on GitHub, pull requests are very welcome!
|
401
|
+
Issues are reported on GitHub, pull requests are very welcome!
|
data/features/support/env.rb
CHANGED
@@ -15,9 +15,7 @@ def file_path( *paths )
|
|
15
15
|
File.expand_path(File.join('..', *paths), File.dirname(__FILE__))
|
16
16
|
end
|
17
17
|
|
18
|
-
CarrierWave.
|
19
|
-
config.root = file_path('public')
|
20
|
-
end
|
18
|
+
CarrierWave.root = file_path('public')
|
21
19
|
|
22
20
|
After do
|
23
21
|
FileUtils.rm_rf(file_path("public"))
|
data/lib/carrierwave.rb
CHANGED
@@ -7,9 +7,11 @@ require 'carrierwave/core_ext/inheritable_attributes'
|
|
7
7
|
|
8
8
|
module CarrierWave
|
9
9
|
|
10
|
-
VERSION = "0.4.
|
10
|
+
VERSION = "0.4.1"
|
11
11
|
|
12
12
|
class << self
|
13
|
+
attr_accessor :root
|
14
|
+
|
13
15
|
def configure(&block)
|
14
16
|
CarrierWave::Uploader::Base.configure(&block)
|
15
17
|
end
|
@@ -24,6 +26,7 @@ module CarrierWave
|
|
24
26
|
autoload :Mount, 'carrierwave/mount'
|
25
27
|
autoload :RMagick, 'carrierwave/processing/rmagick'
|
26
28
|
autoload :ImageScience, 'carrierwave/processing/image_science'
|
29
|
+
autoload :MiniMagick, 'carrierwave/processing/mini_magick'
|
27
30
|
|
28
31
|
module Storage
|
29
32
|
autoload :Abstract, 'carrierwave/storage/abstract'
|
@@ -58,43 +61,24 @@ module CarrierWave
|
|
58
61
|
|
59
62
|
end
|
60
63
|
|
61
|
-
CarrierWave.configure do |config|
|
62
|
-
config.permissions = 0644
|
63
|
-
config.storage_engines = {
|
64
|
-
:file => "CarrierWave::Storage::File",
|
65
|
-
:s3 => "CarrierWave::Storage::S3",
|
66
|
-
:grid_fs => "CarrierWave::Storage::GridFS"
|
67
|
-
}
|
68
|
-
config.storage = :file
|
69
|
-
config.s3_access = :public_read
|
70
|
-
config.grid_fs_database = 'carrierwave'
|
71
|
-
config.grid_fs_host = 'localhost'
|
72
|
-
config.store_dir = 'uploads'
|
73
|
-
config.cache_dir = 'uploads/tmp'
|
74
|
-
config.ignore_integrity_errors = true
|
75
|
-
config.ignore_processing_errors = true
|
76
|
-
config.validate_integrity = true
|
77
|
-
config.validate_processing = true
|
78
|
-
end
|
79
|
-
|
80
64
|
if defined?(Merb)
|
81
|
-
|
82
|
-
|
83
|
-
end
|
65
|
+
|
66
|
+
CarrierWave.root = Merb.dir_for(:public)
|
84
67
|
Merb::BootLoader.before_app_loads do
|
85
68
|
# Setup path for uploaders and load all of them before classes are loaded
|
86
69
|
Merb.push_path(:uploaders, Merb.root / 'app' / 'uploaders', '*.rb')
|
87
70
|
Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
|
88
71
|
end
|
72
|
+
|
89
73
|
elsif defined?(Rails)
|
90
|
-
|
91
|
-
|
92
|
-
end
|
74
|
+
|
75
|
+
CarrierWave.root = File.join(Rails.root, 'public')
|
93
76
|
ActiveSupport::Dependencies.load_paths << File.join(Rails.root, "app", "uploaders")
|
77
|
+
|
94
78
|
elsif defined?(Sinatra)
|
95
|
-
|
96
|
-
|
97
|
-
|
79
|
+
|
80
|
+
CarrierWave.root = Sinatra::Application.public
|
81
|
+
|
98
82
|
end
|
99
83
|
|
100
84
|
|
@@ -7,28 +7,16 @@ module CarrierWave
|
|
7
7
|
include CarrierWave::Mount
|
8
8
|
|
9
9
|
def mount_uploader(column, uploader)
|
10
|
+
raise "You need to use Sequel 3.0 or higher. Please upgrade." unless ::Sequel::Model.respond_to?(:plugin)
|
10
11
|
super
|
11
12
|
|
12
13
|
alias_method :read_uploader, :[]
|
13
14
|
alias_method :write_uploader, :[]=
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
include CarrierWave::Sequel::Validations
|
18
|
-
else
|
19
|
-
after_save "store_#{column}!"
|
20
|
-
before_save "write_#{column}_identifier"
|
21
|
-
before_destroy "remove_#{column}!"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Determine if we're using Sequel > 2.12
|
26
|
-
#
|
27
|
-
# ==== Returns
|
28
|
-
# Bool:: True if Sequel 2.12 or higher False otherwise
|
29
|
-
def self.new_sequel?
|
30
|
-
::Sequel::Model.respond_to?(:plugin)
|
16
|
+
include CarrierWave::Sequel::Hooks
|
17
|
+
include CarrierWave::Sequel::Validations
|
31
18
|
end
|
19
|
+
|
32
20
|
end # Sequel
|
33
21
|
end # CarrierWave
|
34
22
|
|
@@ -5,27 +5,44 @@ require "image_science"
|
|
5
5
|
module CarrierWave
|
6
6
|
module ImageScience
|
7
7
|
|
8
|
-
|
9
|
-
#
|
10
|
-
# the
|
11
|
-
|
8
|
+
##
|
9
|
+
# Resize the image to fit within the specified dimensions while retaining
|
10
|
+
# the original aspect ratio. The image may be shorter or narrower than
|
11
|
+
# specified in the smaller dimension but will not be larger than the
|
12
|
+
# specified values.
|
13
|
+
#
|
14
|
+
# See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fit
|
15
|
+
#
|
16
|
+
# === Parameters
|
17
|
+
#
|
18
|
+
# [width (Integer)] the width to scale the image to
|
19
|
+
# [height (Integer)] the height to scale the image to
|
20
|
+
#
|
21
|
+
def resize_to_fit(new_width, new_height)
|
12
22
|
::ImageScience.with_image(self.current_path) do |img|
|
13
|
-
width, height = extract_dimensions(img.width, img.height,
|
23
|
+
width, height = extract_dimensions(img.width, img.height, new_width, new_height)
|
14
24
|
img.resize( width, height ) do |file|
|
15
25
|
file.save( self.current_path )
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
19
29
|
|
20
|
-
|
21
|
-
#
|
22
|
-
# the
|
23
|
-
|
30
|
+
##
|
31
|
+
# Resize the image to fit within the specified dimensions while retaining
|
32
|
+
# the aspect ratio of the original image. If necessary, crop the image in
|
33
|
+
# the larger dimension.
|
34
|
+
#
|
35
|
+
# See even http://www.imagemagick.org/RMagick/doc/image3.html#resize_to_fill
|
36
|
+
#
|
37
|
+
# === Parameters
|
38
|
+
#
|
39
|
+
# [width (Integer)] the width to scale the image to
|
40
|
+
# [height (Integer)] the height to scale the image to
|
41
|
+
#
|
42
|
+
def resize_to_fill(new_width, new_height)
|
24
43
|
::ImageScience.with_image(self.current_path) do |img|
|
25
|
-
|
26
|
-
|
27
|
-
width, height = extract_dimensions_for_crop(img.width, img.height, geometry)
|
28
|
-
x_offset, y_offset = extract_placement_for_crop(width, height, geometry)
|
44
|
+
width, height = extract_dimensions_for_crop(img.width, img.height, new_width, new_height)
|
45
|
+
x_offset, y_offset = extract_placement_for_crop(width, height, new_width, new_height)
|
29
46
|
|
30
47
|
img.resize( width, height ) do |i2|
|
31
48
|
|
@@ -35,12 +52,29 @@ module CarrierWave
|
|
35
52
|
end
|
36
53
|
end
|
37
54
|
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Resize the image to fit within the specified dimensions while retaining
|
58
|
+
# the original aspect ratio. Will only resize the image if it is larger than the
|
59
|
+
# specified dimensions. The resulting image may be shorter or narrower than specified
|
60
|
+
# in the smaller dimension but will not be larger than the specified values.
|
61
|
+
#
|
62
|
+
# === Parameters
|
63
|
+
#
|
64
|
+
# [width (Integer)] the width to scale the image to
|
65
|
+
# [height (Integer)] the height to scale the image to
|
66
|
+
#
|
67
|
+
def resize_to_limit(new_width, new_height)
|
68
|
+
::ImageScience.with_image(self.current_path) do |img|
|
69
|
+
if img.width > new_width or img.height > new_height
|
70
|
+
resize_to_fit(new_width, new_height)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
38
74
|
|
39
|
-
|
40
|
-
|
41
|
-
def extract_dimensions(width, height, new_geometry, type = :resize)
|
42
|
-
new_width, new_height = convert_geometry(new_geometry)
|
75
|
+
private
|
43
76
|
|
77
|
+
def extract_dimensions(width, height, new_width, new_height, type = :resize)
|
44
78
|
aspect_ratio = width.to_f / height.to_f
|
45
79
|
new_aspect_ratio = new_width / new_height
|
46
80
|
|
@@ -53,20 +87,15 @@ module CarrierWave
|
|
53
87
|
[new_width, new_height].collect! { |v| v.round }
|
54
88
|
end
|
55
89
|
|
56
|
-
def extract_dimensions_for_crop(width, height,
|
57
|
-
extract_dimensions(width, height,
|
90
|
+
def extract_dimensions_for_crop(width, height, new_width, new_height)
|
91
|
+
extract_dimensions(width, height, new_width, new_height, :crop)
|
58
92
|
end
|
59
93
|
|
60
|
-
def extract_placement_for_crop(width, height,
|
61
|
-
new_width, new_height = convert_geometry(new_geometry)
|
94
|
+
def extract_placement_for_crop(width, height, new_width, new_height)
|
62
95
|
x_offset = (width / 2.0) - (new_width / 2.0)
|
63
96
|
y_offset = (height / 2.0) - (new_height / 2.0)
|
64
97
|
[x_offset, y_offset].collect! { |v| v.round }
|
65
98
|
end
|
66
99
|
|
67
|
-
def convert_geometry(geometry)
|
68
|
-
geometry.split('x').map{|i| i.to_f }
|
69
|
-
end
|
70
|
-
|
71
100
|
end # ImageScience
|
72
101
|
end # CarrierWave
|
@@ -5,6 +5,8 @@ unless defined? Magick
|
|
5
5
|
require 'rmagick'
|
6
6
|
rescue LoadError
|
7
7
|
require 'RMagick'
|
8
|
+
rescue LoadError
|
9
|
+
puts "WARNING: Failed to require rmagick, image processing may fail!"
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
@@ -175,8 +177,6 @@ module CarrierWave
|
|
175
177
|
end
|
176
178
|
end
|
177
179
|
|
178
|
-
alias_method :resize, :resize_to_fit
|
179
|
-
|
180
180
|
##
|
181
181
|
# From the RMagick documentation: "Resize the image to fit within the
|
182
182
|
# specified dimensions while retaining the aspect ratio of the original
|
@@ -201,8 +201,6 @@ module CarrierWave
|
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
|
-
alias_method :crop_resized, :resize_to_fill
|
205
|
-
|
206
204
|
##
|
207
205
|
# Resize the image to fit within the specified dimensions while retaining
|
208
206
|
# the original aspect ratio. If necessary, will pad the remaining area
|
@@ -61,23 +61,23 @@ module CarrierWave
|
|
61
61
|
def matches?(actual)
|
62
62
|
@actual = actual
|
63
63
|
# Satisfy expectation here. Return false or raise an error if it's not met.
|
64
|
-
|
65
|
-
img = ::Magick::Image.read(@actual.path).first
|
64
|
+
img = ::Magick::Image.read(@actual.current_path).first
|
66
65
|
@actual_width = img.columns
|
67
66
|
@actual_height = img.rows
|
68
67
|
@actual_width <= @width && @actual_height <= @height
|
69
68
|
end
|
70
69
|
|
71
70
|
def failure_message
|
72
|
-
"expected #{@actual.inspect} to be no larger than #{@width} by #{@height}, but it was #{@
|
71
|
+
"expected #{@actual.current_path.inspect} to be no larger than #{@width} by #{@height}, but it was #{@actual_width} by #{@actual_height}."
|
73
72
|
end
|
74
73
|
|
75
74
|
def negative_failure_message
|
76
|
-
"expected #{@actual.inspect} to be larger than #{@width} by #{@height}, but it wasn't."
|
75
|
+
"expected #{@actual.current_path.inspect} to be larger than #{@width} by #{@height}, but it wasn't."
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
79
|
def be_no_larger_than(width, height)
|
80
|
+
load_rmagick
|
81
81
|
BeNoLargerThan.new(width, height)
|
82
82
|
end
|
83
83
|
|
@@ -89,25 +89,39 @@ module CarrierWave
|
|
89
89
|
def matches?(actual)
|
90
90
|
@actual = actual
|
91
91
|
# Satisfy expectation here. Return false or raise an error if it's not met.
|
92
|
-
|
93
|
-
img = ::Magick::Image.read(@actual.path).first
|
92
|
+
img = ::Magick::Image.read(@actual.current_path).first
|
94
93
|
@actual_width = img.columns
|
95
94
|
@actual_height = img.rows
|
96
95
|
@actual_width == @width && @actual_height == @height
|
97
96
|
end
|
98
97
|
|
99
98
|
def failure_message
|
100
|
-
"expected #{@actual.inspect} to have an exact size of #{@width} by #{@height}, but it was #{@
|
99
|
+
"expected #{@actual.current_path.inspect} to have an exact size of #{@width} by #{@height}, but it was #{@actual_width} by #{@actual_height}."
|
101
100
|
end
|
102
101
|
|
103
102
|
def negative_failure_message
|
104
|
-
"expected #{@actual.inspect} not to have an exact size of #{@width} by #{@height}, but it did."
|
103
|
+
"expected #{@actual.current_path.inspect} not to have an exact size of #{@width} by #{@height}, but it did."
|
105
104
|
end
|
106
105
|
end
|
107
106
|
|
108
107
|
def have_dimensions(width, height)
|
108
|
+
load_rmagick
|
109
109
|
HaveDimensions.new(width, height)
|
110
110
|
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def load_rmagick
|
115
|
+
unless defined? Magick
|
116
|
+
begin
|
117
|
+
require 'rmagick'
|
118
|
+
rescue LoadError
|
119
|
+
require 'RMagick'
|
120
|
+
rescue LoadError
|
121
|
+
puts "WARNING: Failed to require rmagick, image processing may fail!"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
111
125
|
|
112
126
|
end # SpecHelper
|
113
127
|
end # Test
|
@@ -2,7 +2,6 @@ module CarrierWave
|
|
2
2
|
|
3
3
|
module Uploader
|
4
4
|
module Configuration
|
5
|
-
|
6
5
|
setup do
|
7
6
|
add_config :root
|
8
7
|
add_config :permissions
|
@@ -24,18 +23,75 @@ module CarrierWave
|
|
24
23
|
add_config :validate_integrity
|
25
24
|
add_config :validate_processing
|
26
25
|
add_config :mount_on
|
26
|
+
|
27
|
+
configure do |config|
|
28
|
+
config.permissions = 0644
|
29
|
+
config.storage_engines = {
|
30
|
+
:file => "CarrierWave::Storage::File",
|
31
|
+
:s3 => "CarrierWave::Storage::S3",
|
32
|
+
:grid_fs => "CarrierWave::Storage::GridFS"
|
33
|
+
}
|
34
|
+
config.storage = :file
|
35
|
+
config.s3_access = :public_read
|
36
|
+
config.grid_fs_database = 'carrierwave'
|
37
|
+
config.grid_fs_host = 'localhost'
|
38
|
+
config.store_dir = 'uploads'
|
39
|
+
config.cache_dir = 'uploads/tmp'
|
40
|
+
config.ignore_integrity_errors = true
|
41
|
+
config.ignore_processing_errors = true
|
42
|
+
config.validate_integrity = true
|
43
|
+
config.validate_processing = true
|
44
|
+
config.root = CarrierWave.root
|
45
|
+
end
|
27
46
|
end
|
28
47
|
|
29
48
|
module ClassMethods
|
30
49
|
|
50
|
+
##
|
51
|
+
# Sets the storage engine to be used when storing files with this uploader.
|
52
|
+
# Can be any class that implements a #store!(CarrierWave::SanitizedFile) and a #retrieve!
|
53
|
+
# method. See lib/carrierwave/storage/file.rb for an example. Storage engines should
|
54
|
+
# be added to CarrierWave::Uploader::Base.storage_engines so they can be referred
|
55
|
+
# to by a symbol, which should be more convenient
|
56
|
+
#
|
57
|
+
# If no argument is given, it will simply return the currently used storage engine.
|
58
|
+
#
|
59
|
+
# === Parameters
|
60
|
+
#
|
61
|
+
# [storage (Symbol, Class)] The storage engine to use for this uploader
|
62
|
+
#
|
63
|
+
# === Returns
|
64
|
+
#
|
65
|
+
# [Class] the storage engine to be used with this uploader
|
66
|
+
#
|
67
|
+
# === Examples
|
68
|
+
#
|
69
|
+
# storage :file
|
70
|
+
# storage CarrierWave::Storage::File
|
71
|
+
# storage MyCustomStorageEngine
|
72
|
+
#
|
73
|
+
def storage(storage = nil)
|
74
|
+
if storage.is_a?(Symbol)
|
75
|
+
@storage = eval(storage_engines[storage])
|
76
|
+
elsif storage
|
77
|
+
@storage = storage
|
78
|
+
elsif @storage.nil?
|
79
|
+
# Get the storage from the superclass if there is one
|
80
|
+
@storage = superclass.storage rescue nil
|
81
|
+
end
|
82
|
+
return @storage
|
83
|
+
end
|
84
|
+
alias_method :storage=, :storage
|
85
|
+
|
86
|
+
|
31
87
|
def add_config(name)
|
32
88
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
33
89
|
def self.#{name}(value=nil)
|
34
90
|
@#{name} = value if value
|
35
91
|
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
|
36
92
|
name = superclass.#{name}
|
37
|
-
return nil if name.nil? &&
|
38
|
-
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
93
|
+
return nil if name.nil? && !instance_variable_defined?("@#{name}")
|
94
|
+
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
39
95
|
end
|
40
96
|
|
41
97
|
def self.#{name}=(value)
|
@@ -8,46 +8,6 @@ module CarrierWave
|
|
8
8
|
depends_on CarrierWave::Uploader::Configuration
|
9
9
|
depends_on CarrierWave::Uploader::Cache
|
10
10
|
|
11
|
-
module ClassMethods
|
12
|
-
|
13
|
-
##
|
14
|
-
# Sets the storage engine to be used when storing files with this uploader.
|
15
|
-
# Can be any class that implements a #store!(CarrierWave::SanitizedFile) and a #retrieve!
|
16
|
-
# method. See lib/carrierwave/storage/file.rb for an example. Storage engines should
|
17
|
-
# be added to CarrierWave::Uploader::Base.storage_engines so they can be referred
|
18
|
-
# to by a symbol, which should be more convenient
|
19
|
-
#
|
20
|
-
# If no argument is given, it will simply return the currently used storage engine.
|
21
|
-
#
|
22
|
-
# === Parameters
|
23
|
-
#
|
24
|
-
# [storage (Symbol, Class)] The storage engine to use for this uploader
|
25
|
-
#
|
26
|
-
# === Returns
|
27
|
-
#
|
28
|
-
# [Class] the storage engine to be used with this uploader
|
29
|
-
#
|
30
|
-
# === Examples
|
31
|
-
#
|
32
|
-
# storage :file
|
33
|
-
# storage CarrierWave::Storage::File
|
34
|
-
# storage MyCustomStorageEngine
|
35
|
-
#
|
36
|
-
def storage(storage = nil)
|
37
|
-
if storage.is_a?(Symbol)
|
38
|
-
@storage = eval(storage_engines[storage])
|
39
|
-
elsif storage
|
40
|
-
@storage = storage
|
41
|
-
elsif @storage.nil?
|
42
|
-
# Get the storage from the superclass if there is one
|
43
|
-
@storage = superclass.storage rescue nil
|
44
|
-
end
|
45
|
-
return @storage
|
46
|
-
end
|
47
|
-
alias_method :storage=, :storage
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
11
|
##
|
52
12
|
# Override this in your Uploader to change the filename.
|
53
13
|
#
|
data/spec/orm/sequel_spec.rb
CHANGED
@@ -111,18 +111,9 @@ describe CarrierWave::Sequel do
|
|
111
111
|
describe 'with validation' do
|
112
112
|
|
113
113
|
before do
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
def validate
|
118
|
-
errors.add(:image, 'FAIL!')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
else
|
122
|
-
@class.class_eval do
|
123
|
-
validates_each(:image) do |o,a,v|
|
124
|
-
o.errors.add(a, 'FAIL!')
|
125
|
-
end
|
114
|
+
@class.class_eval do
|
115
|
+
def validate
|
116
|
+
errors.add(:image, 'FAIL!')
|
126
117
|
end
|
127
118
|
end
|
128
119
|
# Turn off raising the exceptions on save
|
data/spec/spec_helper.rb
CHANGED
@@ -34,6 +34,38 @@ describe CarrierWave::Uploader::Base do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
describe ".storage" do
|
38
|
+
it "should set the storage if an argument is given" do
|
39
|
+
storage = mock('some kind of storage')
|
40
|
+
@uploader_class.storage storage
|
41
|
+
@uploader_class.storage.should == storage
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should default to file" do
|
45
|
+
@uploader_class.storage.should == CarrierWave::Storage::File
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should set the storage from the configured shortcuts if a symbol is given" do
|
49
|
+
@uploader_class.storage :file
|
50
|
+
@uploader_class.storage.should == CarrierWave::Storage::File
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should remember the storage when inherited" do
|
54
|
+
@uploader_class.storage :s3
|
55
|
+
subclass = Class.new(@uploader_class)
|
56
|
+
subclass.storage.should == CarrierWave::Storage::S3
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be changeable when inherited" do
|
60
|
+
@uploader_class.storage :s3
|
61
|
+
subclass = Class.new(@uploader_class)
|
62
|
+
subclass.storage.should == CarrierWave::Storage::S3
|
63
|
+
subclass.storage :file
|
64
|
+
subclass.storage.should == CarrierWave::Storage::File
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
37
69
|
describe '.add_config' do
|
38
70
|
it "should add a class level accessor" do
|
39
71
|
@uploader_class.add_config :foo_bar
|
@@ -41,21 +73,23 @@ describe CarrierWave::Uploader::Base do
|
|
41
73
|
@uploader_class.foo_bar.should == 'foo'
|
42
74
|
end
|
43
75
|
|
44
|
-
|
45
|
-
|
46
|
-
|
76
|
+
['foo', :foo, 45, ['foo', :bar]].each do |val|
|
77
|
+
it "should be inheritable for a #{val.class}" do
|
78
|
+
@uploader_class.add_config :foo_bar
|
79
|
+
@child_class = Class.new(@uploader_class)
|
47
80
|
|
48
|
-
|
49
|
-
|
81
|
+
@uploader_class.foo_bar = val
|
82
|
+
@uploader_class.foo_bar.should == val
|
83
|
+
@child_class.foo_bar.should == val
|
50
84
|
|
51
|
-
|
85
|
+
@child_class.foo_bar = "bar"
|
86
|
+
@child_class.foo_bar.should == "bar"
|
52
87
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
@uploader_class.foo_bar.should == 'foo'
|
88
|
+
@uploader_class.foo_bar.should == val
|
89
|
+
end
|
57
90
|
end
|
58
91
|
|
92
|
+
|
59
93
|
it "should add an instance level accessor" do
|
60
94
|
@uploader_class.add_config :foo_bar
|
61
95
|
@uploader_class.foo_bar = 'foo'
|
data/spec/uploader/store_spec.rb
CHANGED
@@ -13,37 +13,6 @@ describe CarrierWave::Uploader do
|
|
13
13
|
FileUtils.rm_rf(public_path)
|
14
14
|
end
|
15
15
|
|
16
|
-
describe ".storage" do
|
17
|
-
it "should set the storage if an argument is given" do
|
18
|
-
storage = mock('some kind of storage')
|
19
|
-
@uploader_class.storage storage
|
20
|
-
@uploader_class.storage.should == storage
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should default to file" do
|
24
|
-
@uploader_class.storage.should == CarrierWave::Storage::File
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should set the storage from the configured shortcuts if a symbol is given" do
|
28
|
-
@uploader_class.storage :file
|
29
|
-
@uploader_class.storage.should == CarrierWave::Storage::File
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should remember the storage when inherited" do
|
33
|
-
@uploader_class.storage :s3
|
34
|
-
subclass = Class.new(@uploader_class)
|
35
|
-
subclass.storage.should == CarrierWave::Storage::S3
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should be changeable when inherited" do
|
39
|
-
@uploader_class.storage :s3
|
40
|
-
subclass = Class.new(@uploader_class)
|
41
|
-
subclass.storage.should == CarrierWave::Storage::S3
|
42
|
-
subclass.storage :file
|
43
|
-
subclass.storage.should == CarrierWave::Storage::File
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
16
|
describe '#store_dir' do
|
48
17
|
it "should default to the config option" do
|
49
18
|
@uploader.store_dir.should == 'uploads'
|
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.4.
|
4
|
+
version: 0.4.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-10-
|
12
|
+
date: 2009-10-26 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|