jnicklas-carrierwave 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/carrierwave.rb +3 -0
- data/lib/carrierwave/compatibility/paperclip.rb +2 -0
- data/lib/carrierwave/core_ext/blank.rb +46 -0
- data/lib/carrierwave/core_ext/inheritable_attributes.rb +2 -0
- data/lib/carrierwave/core_ext/module_setup.rb +2 -0
- data/lib/carrierwave/mount.rb +2 -0
- data/lib/carrierwave/orm/activerecord.rb +2 -0
- data/lib/carrierwave/orm/datamapper.rb +2 -0
- data/lib/carrierwave/orm/sequel.rb +37 -12
- data/lib/carrierwave/processing/image_science.rb +2 -0
- data/lib/carrierwave/processing/rmagick.rb +2 -0
- data/lib/carrierwave/sanitized_file.rb +4 -0
- data/lib/carrierwave/storage/abstract.rb +2 -0
- data/lib/carrierwave/storage/file.rb +2 -0
- data/lib/carrierwave/storage/s3.rb +28 -5
- data/lib/carrierwave/test/matchers.rb +2 -0
- data/lib/carrierwave/uploader.rb +2 -0
- data/lib/carrierwave/uploader/cache.rb +2 -0
- data/lib/carrierwave/uploader/callbacks.rb +2 -0
- data/lib/carrierwave/uploader/default_path.rb +2 -0
- data/lib/carrierwave/uploader/extension_whitelist.rb +2 -0
- data/lib/carrierwave/uploader/mountable.rb +2 -0
- data/lib/carrierwave/uploader/paths.rb +2 -0
- data/lib/carrierwave/uploader/processing.rb +2 -0
- data/lib/carrierwave/uploader/proxy.rb +2 -0
- data/lib/carrierwave/uploader/remove.rb +2 -0
- data/lib/carrierwave/uploader/store.rb +2 -0
- data/lib/carrierwave/uploader/url.rb +2 -0
- data/lib/carrierwave/uploader/versions.rb +2 -0
- data/lib/generators/uploader_generator.rb +2 -0
- data/rails_generators/uploader/templates/uploader.rb +2 -0
- data/rails_generators/uploader/uploader_generator.rb +2 -0
- data/spec/compatibility/paperclip_spec.rb +2 -0
- data/spec/mount_spec.rb +2 -0
- data/spec/orm/activerecord_spec.rb +5 -3
- data/spec/orm/datamapper_spec.rb +5 -3
- data/spec/orm/sequel_spec.rb +8 -4
- data/spec/sanitized_file_spec.rb +2 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/uploader/cache_spec.rb +2 -0
- data/spec/uploader/default_path_spec.rb +2 -0
- data/spec/uploader/extension_whitelist_spec.rb +2 -0
- data/spec/uploader/mountable_spec.rb +2 -0
- data/spec/uploader/paths_spec.rb +2 -0
- data/spec/uploader/processing_spec.rb +2 -0
- data/spec/uploader/proxy_spec.rb +2 -0
- data/spec/uploader/remove_spec.rb +2 -0
- data/spec/uploader/store_spec.rb +2 -0
- data/spec/uploader/url_spec.rb +2 -0
- data/spec/uploader/versions_spec.rb +2 -0
- metadata +3 -2
data/Rakefile
CHANGED
data/lib/carrierwave.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
unless "".respond_to?(:blank?)
|
4
|
+
# blank? methods for several different class types
|
5
|
+
class Object
|
6
|
+
# Returns true if the object is nil or empty (if applicable)
|
7
|
+
def blank?
|
8
|
+
nil? || (respond_to?(:empty?) && empty?)
|
9
|
+
end
|
10
|
+
end # class Object
|
11
|
+
|
12
|
+
class Numeric
|
13
|
+
# Numerics can't be blank
|
14
|
+
def blank?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end # class Numeric
|
18
|
+
|
19
|
+
class NilClass
|
20
|
+
# Nils are always blank
|
21
|
+
def blank?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end # class NilClass
|
25
|
+
|
26
|
+
class TrueClass
|
27
|
+
# True is not blank.
|
28
|
+
def blank?
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end # class TrueClass
|
32
|
+
|
33
|
+
class FalseClass
|
34
|
+
# False is always blank.
|
35
|
+
def blank?
|
36
|
+
true
|
37
|
+
end
|
38
|
+
end # class FalseClass
|
39
|
+
|
40
|
+
class String
|
41
|
+
# Strips out whitespace then tests if the string is empty.
|
42
|
+
def blank?
|
43
|
+
strip.empty?
|
44
|
+
end
|
45
|
+
end # class String
|
46
|
+
end
|
data/lib/carrierwave/mount.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'sequel'
|
4
|
+
|
3
5
|
module CarrierWave
|
4
6
|
module Sequel
|
5
|
-
|
6
7
|
include CarrierWave::Mount
|
7
|
-
|
8
|
+
|
8
9
|
def mount_uploader(column, uploader)
|
9
10
|
super
|
10
|
-
|
11
|
+
|
11
12
|
alias_method :read_uploader, :[]
|
12
13
|
alias_method :write_uploader, :[]=
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
if CarrierWave::Sequel.new_sequel?
|
16
|
+
include CarrierWave::Sequel::Hooks
|
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
|
17
23
|
end
|
18
|
-
|
24
|
+
|
19
25
|
# Determine if we're using Sequel > 2.12
|
20
26
|
#
|
21
27
|
# ==== Returns
|
@@ -23,10 +29,29 @@ module CarrierWave
|
|
23
29
|
def self.new_sequel?
|
24
30
|
::Sequel::Model.respond_to?(:plugin)
|
25
31
|
end
|
26
|
-
|
27
32
|
end # Sequel
|
28
33
|
end # CarrierWave
|
34
|
+
|
35
|
+
# Instance hook methods for the Sequel 3.x
|
36
|
+
module CarrierWave::Sequel::Hooks
|
37
|
+
def after_save
|
38
|
+
return false if super == false
|
39
|
+
self.class.uploaders.each_key {|column| self.send("store_#{column}!") }
|
40
|
+
end
|
41
|
+
|
42
|
+
def before_save
|
43
|
+
return false if super == false
|
44
|
+
self.class.uploaders.each_key {|column| self.send("write_#{column}_identifier") }
|
45
|
+
end
|
46
|
+
|
47
|
+
def before_destroy
|
48
|
+
return false if super == false
|
49
|
+
self.class.uploaders.each_key {|column| self.send("remove_#{column}!") }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Instance validation methods for the Sequel 3.x
|
54
|
+
module CarrierWave::Sequel::Validations
|
55
|
+
end
|
29
56
|
|
30
|
-
# Sequel 3.x.x removed class hook methods and moved them to the plugin
|
31
|
-
Sequel::Model.plugin(:hook_class_methods) if CarrierWave::Sequel.new_sequel?
|
32
57
|
Sequel::Model.send(:extend, CarrierWave::Sequel)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
module CarrierWave
|
2
4
|
module Storage
|
3
5
|
|
@@ -87,20 +89,41 @@ module CarrierWave
|
|
87
89
|
["http://s3.amazonaws.com", bucket, @path].compact.join('/')
|
88
90
|
end
|
89
91
|
|
90
|
-
def
|
91
|
-
|
92
|
+
def about
|
93
|
+
s3_object.about
|
92
94
|
end
|
93
95
|
|
94
|
-
|
96
|
+
def metadata
|
97
|
+
s3_object.metadata
|
98
|
+
end
|
99
|
+
|
100
|
+
def content_type
|
101
|
+
s3_object.content_type
|
102
|
+
end
|
103
|
+
|
104
|
+
def content_type=(new_content_type)
|
105
|
+
s3_object.content_type = new_content_type
|
106
|
+
end
|
95
107
|
|
96
|
-
def
|
97
|
-
s3_object.
|
108
|
+
def content_disposition
|
109
|
+
s3_object.content_disposition
|
110
|
+
end
|
111
|
+
|
112
|
+
def content_disposition=(new_disposition)
|
113
|
+
s3_object.content_disposition = new_disposition
|
114
|
+
end
|
115
|
+
|
116
|
+
def store
|
117
|
+
s3_object.store
|
98
118
|
end
|
99
119
|
|
100
120
|
def s3_object
|
101
121
|
@s3_object ||= AWS::S3::S3Object.find(@path, bucket)
|
102
122
|
end
|
103
123
|
|
124
|
+
|
125
|
+
private
|
126
|
+
|
104
127
|
def bucket
|
105
128
|
CarrierWave::Storage::S3.bucket
|
106
129
|
end
|
data/lib/carrierwave/uploader.rb
CHANGED
data/spec/mount_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
4
|
|
3
5
|
require 'carrierwave/orm/activerecord'
|
@@ -52,11 +54,11 @@ describe CarrierWave::ActiveRecord do
|
|
52
54
|
|
53
55
|
describe '#image' do
|
54
56
|
|
55
|
-
it "should return
|
57
|
+
it "should return blank uploader when nothing has been assigned" do
|
56
58
|
@event.image.should be_blank
|
57
59
|
end
|
58
60
|
|
59
|
-
it "should return
|
61
|
+
it "should return blank uploader when an empty string has been assigned" do
|
60
62
|
@event[:image] = ''
|
61
63
|
@event.save
|
62
64
|
@event.reload
|
@@ -266,4 +268,4 @@ describe CarrierWave::ActiveRecord do
|
|
266
268
|
|
267
269
|
end
|
268
270
|
|
269
|
-
end
|
271
|
+
end
|
data/spec/orm/datamapper_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
4
|
|
3
5
|
require 'carrierwave/orm/datamapper'
|
@@ -30,11 +32,11 @@ describe CarrierWave::DataMapper do
|
|
30
32
|
|
31
33
|
describe '#image' do
|
32
34
|
|
33
|
-
it "should return
|
35
|
+
it "should return blank uploader when nothing has been assigned" do
|
34
36
|
@event.image.should be_blank
|
35
37
|
end
|
36
38
|
|
37
|
-
it "should return
|
39
|
+
it "should return blank uploader when an empty string has been assigned" do
|
38
40
|
repository(:default).adapter.query("INSERT INTO events (image) VALUES ('')")
|
39
41
|
@event = @class.first
|
40
42
|
|
@@ -156,4 +158,4 @@ describe CarrierWave::DataMapper do
|
|
156
158
|
|
157
159
|
end
|
158
160
|
|
159
|
-
end
|
161
|
+
end
|
data/spec/orm/sequel_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
4
|
|
3
5
|
require 'carrierwave/orm/sequel'
|
@@ -27,19 +29,21 @@ describe CarrierWave::Sequel do
|
|
27
29
|
DB.drop_table :events
|
28
30
|
end
|
29
31
|
|
30
|
-
before do
|
32
|
+
before(:each) do
|
31
33
|
@class = Class.new(Sequel::Model)
|
32
34
|
@class.set_dataset :events
|
33
35
|
@class, @uploader, @event = setup_variables_for_class(@class)
|
34
36
|
end
|
37
|
+
|
38
|
+
after(:each) { @class.delete }
|
35
39
|
|
36
40
|
describe '#image' do
|
37
41
|
|
38
|
-
it "should return
|
42
|
+
it "should return blank uploader when nothing has been assigned" do
|
39
43
|
@event.image.should be_blank
|
40
44
|
end
|
41
45
|
|
42
|
-
it "should return
|
46
|
+
it "should return blank uploader when an empty string has been assigned" do
|
43
47
|
@event[:image] = ''
|
44
48
|
@event.save
|
45
49
|
@event.reload
|
@@ -87,7 +91,7 @@ describe CarrierWave::Sequel do
|
|
87
91
|
@event.image = ''
|
88
92
|
@event.image.should be_blank
|
89
93
|
end
|
90
|
-
|
94
|
+
|
91
95
|
end
|
92
96
|
|
93
97
|
describe '#save' do
|
data/spec/sanitized_file_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
$TESTING=true
|
2
|
-
$:.
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
5
|
|
4
6
|
require 'rubygems'
|
5
7
|
|
6
8
|
if ENV["AS"]
|
7
9
|
puts "--> using ActiveSupport"
|
8
10
|
require 'activesupport'
|
9
|
-
|
11
|
+
elsif ENV["EXTLIB"]
|
10
12
|
puts "--> using Extlib"
|
11
13
|
require 'extlib'
|
12
14
|
end
|
data/spec/uploader/cache_spec.rb
CHANGED
data/spec/uploader/paths_spec.rb
CHANGED
data/spec/uploader/proxy_spec.rb
CHANGED
data/spec/uploader/store_spec.rb
CHANGED
data/spec/uploader/url_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jnicklas-carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
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-07-
|
12
|
+
date: 2009-07-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/carrierwave/compatibility
|
34
34
|
- lib/carrierwave/compatibility/paperclip.rb
|
35
35
|
- lib/carrierwave/core_ext
|
36
|
+
- lib/carrierwave/core_ext/blank.rb
|
36
37
|
- lib/carrierwave/core_ext/inheritable_attributes.rb
|
37
38
|
- lib/carrierwave/core_ext/module_setup.rb
|
38
39
|
- lib/carrierwave/mount.rb
|