paperclip-cloudfiles 2.3.8 → 2.3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{README.rdoc → README.md} +82 -55
- data/lib/paperclip/attachment.rb +3 -0
- data/lib/paperclip/storage/cloud_files.rb +9 -2
- data/lib/paperclip/version.rb +1 -1
- data/test/integration_test.rb +16 -0
- data/test/storage_test.rb +23 -0
- metadata +32 -31
data/{README.rdoc → README.md}
RENAMED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
Paperclip
|
2
|
+
=========
|
2
3
|
|
3
4
|
Paperclip is intended as an easy file attachment library for ActiveRecord. The
|
4
5
|
intent behind it was to keep setup as easy as possible and to treat files as
|
@@ -12,7 +13,7 @@ packages). Attached files are saved to the filesystem and referenced in the
|
|
12
13
|
browser by an easily understandable specification, which has sensible and
|
13
14
|
useful defaults.
|
14
15
|
|
15
|
-
See the documentation for
|
16
|
+
See the documentation for `has_attached_file` in Paperclip::ClassMethods for
|
16
17
|
more detailed options.
|
17
18
|
|
18
19
|
This fork has support for Rackspace Cloud Files. It requires the "cloudfiles"
|
@@ -22,71 +23,76 @@ personally use on projects, so until they discover the joy of Cloud Files, this
|
|
22
23
|
fork is available as the {paperclip-cloudfiles gem}[http://gemcutter.org/gems/paperclip-cloudfiles]
|
23
24
|
on Gemcutter's gem server.
|
24
25
|
|
25
|
-
|
26
|
+
The complete [RDoc](http://rdoc.info/github/minter/paperclip) is online.
|
27
|
+
|
28
|
+
Installation
|
29
|
+
------------
|
26
30
|
|
27
31
|
Include the gem in your Gemfile:
|
28
32
|
|
29
33
|
gem "paperclip-cloudfiles", "~> 2.3"
|
30
34
|
|
31
|
-
==Quick Start
|
32
|
-
|
33
35
|
In your environment.rb:
|
34
36
|
|
35
37
|
config.gem "paperclip-cloudfiles", :lib => 'paperclip'
|
36
38
|
|
37
39
|
This is because the gem name and the library name don't match.
|
38
40
|
|
41
|
+
Quick Start
|
42
|
+
-----------
|
43
|
+
|
39
44
|
In your model:
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
class User < ActiveRecord::Base
|
47
|
+
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
|
48
|
+
end
|
44
49
|
|
45
50
|
In your migrations:
|
46
51
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
class AddAvatarColumnsToUser < ActiveRecord::Migration
|
53
|
+
def self.up
|
54
|
+
add_column :users, :avatar_file_name, :string
|
55
|
+
add_column :users, :avatar_content_type, :string
|
56
|
+
add_column :users, :avatar_file_size, :integer
|
57
|
+
add_column :users, :avatar_updated_at, :datetime
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.down
|
61
|
+
remove_column :users, :avatar_file_name
|
62
|
+
remove_column :users, :avatar_content_type
|
63
|
+
remove_column :users, :avatar_file_size
|
64
|
+
remove_column :users, :avatar_updated_at
|
65
|
+
end
|
53
66
|
end
|
54
67
|
|
55
|
-
def self.down
|
56
|
-
remove_column :users, :avatar_file_name
|
57
|
-
remove_column :users, :avatar_content_type
|
58
|
-
remove_column :users, :avatar_file_size
|
59
|
-
remove_column :users, :avatar_updated_at
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
68
|
In your edit and new views:
|
64
69
|
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
<% form_for :user, @user, :url => user_path, :html => { :multipart => true } do |form| %>
|
71
|
+
<%= form.file_field :avatar %>
|
72
|
+
<% end %>
|
68
73
|
|
69
74
|
In your controller:
|
70
75
|
|
71
|
-
|
72
|
-
|
73
|
-
|
76
|
+
def create
|
77
|
+
@user = User.create( params[:user] )
|
78
|
+
end
|
74
79
|
|
75
80
|
In your show view:
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
<%= image_tag @user.avatar.url %>
|
83
|
+
<%= image_tag @user.avatar.url(:medium) %>
|
84
|
+
<%= image_tag @user.avatar.url(:thumb) %>
|
80
85
|
|
81
|
-
|
86
|
+
Usage
|
87
|
+
-----
|
82
88
|
|
83
89
|
The basics of paperclip are quite simple: Declare that your model has an
|
84
90
|
attachment with the has_attached_file method, and give it a name. Paperclip
|
85
91
|
will wrap up up to four attributes (all prefixed with that attachment's name,
|
86
92
|
so you can have multiple attachments per model if you wish) and give the a
|
87
|
-
friendly front end. The attributes are
|
88
|
-
|
89
|
-
Only
|
93
|
+
friendly front end. The attributes are `<attachment>_file_name`,
|
94
|
+
`<attachment>_file_size`, `<attachment>_content_type`, and `<attachment>_updated_at`.
|
95
|
+
Only `<attachment>_file_name` is required for paperclip to operate. More
|
90
96
|
information about the options to has_attached_file is available in the
|
91
97
|
documentation of Paperclip::ClassMethods.
|
92
98
|
|
@@ -94,7 +100,8 @@ Attachments can be validated with Paperclip's validation methods,
|
|
94
100
|
validates_attachment_presence, validates_attachment_content_type, and
|
95
101
|
validates_attachment_size.
|
96
102
|
|
97
|
-
|
103
|
+
Storage
|
104
|
+
-------
|
98
105
|
|
99
106
|
The files that are assigned as attachments are, by default, placed in the
|
100
107
|
directory specified by the :path option to has_attached_file. By default, this
|
@@ -104,10 +111,10 @@ public/system directory is symlinked to the app's shared directory, meaning it
|
|
104
111
|
will survive between deployments. For example, using that :path, you may have a
|
105
112
|
file at
|
106
113
|
|
107
|
-
|
114
|
+
/data/myapp/releases/20081229172410/public/system/avatars/13/small/my_pic.png
|
108
115
|
|
109
|
-
|
110
|
-
safer choice for the default file store.
|
116
|
+
_NOTE: This is a change from previous versions of Paperclip, but is overall a
|
117
|
+
safer choice for the default file store._
|
111
118
|
|
112
119
|
You may also choose to store your files using Amazon's S3 service or Rackspace's Cloud Files service. You can find
|
113
120
|
more information about S3 storage at the description for Paperclip::Storage::S3. and more information about Cloud Files storage at the description for Paperclip::Storage::CloudFile
|
@@ -119,7 +126,8 @@ both the :path and :url options in order to make sure the files are unavailable
|
|
119
126
|
to the public. Both :path and :url allow the same set of interpolated
|
120
127
|
variables.
|
121
128
|
|
122
|
-
|
129
|
+
Post Processing
|
130
|
+
---------------
|
123
131
|
|
124
132
|
Paperclip supports an extensible selection of post-processors. When you define
|
125
133
|
a set of styles for an attachment, by default it is expected that those
|
@@ -130,8 +138,8 @@ your Rails app's lib/paperclip_processors directory is automatically loaded by
|
|
130
138
|
paperclip, allowing you to easily define custom processors. You can specify a
|
131
139
|
processor with the :processors option to has_attached_file:
|
132
140
|
|
133
|
-
|
134
|
-
|
141
|
+
has_attached_file :scan, :styles => { :text => { :quality => :better } },
|
142
|
+
:processors => [:ocr]
|
135
143
|
|
136
144
|
This would load the hypothetical class Paperclip::Ocr, which would have the
|
137
145
|
hash "{ :quality => :better }" passed to it along with the uploaded file. For
|
@@ -141,7 +149,7 @@ The default processor is Paperclip::Thumbnail. For backwards compatability
|
|
141
149
|
reasons, you can pass a single geometry string or an array containing a
|
142
150
|
geometry and a format, which the file will be converted to, like so:
|
143
151
|
|
144
|
-
|
152
|
+
has_attached_file :avatar, :styles => { :thumb => ["32x32#", :png] }
|
145
153
|
|
146
154
|
This will convert the "thumb" style to a 32x32 square in png format, regardless
|
147
155
|
of what was uploaded. If the format is not specified, it is kept the same (i.e.
|
@@ -153,39 +161,42 @@ be given the result of the previous processor's execution. All processors will
|
|
153
161
|
receive the same parameters, which are what you define in the :styles hash.
|
154
162
|
For example, assuming we had this definition:
|
155
163
|
|
156
|
-
|
157
|
-
|
164
|
+
has_attached_file :scan, :styles => { :text => { :quality => :better } },
|
165
|
+
:processors => [:rotator, :ocr]
|
158
166
|
|
159
167
|
then both the :rotator processor and the :ocr processor would receive the
|
160
168
|
options "{ :quality => :better }". This parameter may not mean anything to one
|
161
169
|
or more or the processors, and they are expected to ignore it.
|
162
170
|
|
163
|
-
|
164
|
-
styles, no processors will be run if there are no styles defined.
|
171
|
+
_NOTE: Because processors operate by turning the original attachment into the
|
172
|
+
styles, no processors will be run if there are no styles defined._
|
165
173
|
|
166
|
-
|
174
|
+
Events
|
175
|
+
------
|
167
176
|
|
168
177
|
Before and after the Post Processing step, Paperclip calls back to the model
|
169
178
|
with a few callbacks, allowing the model to change or cancel the processing
|
170
|
-
step. The callbacks are
|
179
|
+
step. The callbacks are `before_post_process` and `after_post_process` (which
|
171
180
|
are called before and after the processing of each attachment), and the
|
172
|
-
attachment-specific
|
173
|
-
|
181
|
+
attachment-specific `before_<attachment>_post_process` and
|
182
|
+
`after_<attachment>_post_process`. The callbacks are intended to be as close to
|
174
183
|
normal ActiveRecord callbacks as possible, so if you return false (specifically
|
175
184
|
- returning nil is not the same) in a before_ filter, the post processing step
|
176
185
|
will halt. Returning false in an after_ filter will not halt anything, but you
|
177
186
|
can access the model and the attachment if necessary.
|
178
187
|
|
179
|
-
|
188
|
+
_NOTE: Post processing will not even *start* if the attachment is not valid
|
180
189
|
according to the validations. Your callbacks and processors will *only* be
|
181
|
-
called with valid attachments.
|
190
|
+
called with valid attachments._
|
182
191
|
|
183
|
-
|
192
|
+
Testing
|
193
|
+
-------
|
184
194
|
|
185
195
|
Paperclip provides rspec-compatible matchers for testing attachments. See the
|
186
196
|
documentation on Paperclip::Shoulda::Matchers for more information.
|
187
197
|
|
188
|
-
|
198
|
+
Contributing
|
199
|
+
------------
|
189
200
|
|
190
201
|
If you'd like to contribute a feature or bugfix: Thanks! To make sure your
|
191
202
|
fix/feature has a high chance of being included, please read the following
|
@@ -196,3 +207,19 @@ guidelines:
|
|
196
207
|
2. Make sure there are tests! We will not accept any patch that is not tested.
|
197
208
|
It's a rare time when explicit tests aren't needed. If you have questions
|
198
209
|
about writing tests for paperclip, please ask the mailing list.
|
210
|
+
|
211
|
+
Credits
|
212
|
+
-------
|
213
|
+
|
214
|
+

|
215
|
+
|
216
|
+
Paperclip is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
|
217
|
+
|
218
|
+
Thank you to all [the contributors](https://github.com/thoughtbot/paperclip/contributors)!
|
219
|
+
|
220
|
+
The names and logos for thoughtbot are trademarks of thoughtbot, inc.
|
221
|
+
|
222
|
+
License
|
223
|
+
-------
|
224
|
+
|
225
|
+
Paperclip is Copyright © 2008-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
|
data/lib/paperclip/attachment.rb
CHANGED
@@ -24,6 +24,7 @@ module Paperclip
|
|
24
24
|
# username: minter
|
25
25
|
# api_key: 87k...
|
26
26
|
# servicenet: true
|
27
|
+
# auth_url: https://lon.auth.api.rackspacecloud.com/v1.0
|
27
28
|
# This is not required, however, and the file may simply look like this:
|
28
29
|
# username: minter...
|
29
30
|
# api_key: 11q...
|
@@ -39,13 +40,16 @@ module Paperclip
|
|
39
40
|
# you will want to interpolate. Keys should be unique, like filenames, and despite the fact that
|
40
41
|
# Cloud Files (strictly speaking) does not support directories, you can still use a / to
|
41
42
|
# separate parts of your file name, and they will show up in the URL structure.
|
43
|
+
# * +auth_url+: The URL to the authentication endpoint. If blank, defaults to the Rackspace Cloud Files
|
44
|
+
# USA endpoint. You can use this to specify things like the Rackspace Cloud Files UK infrastructure, or
|
45
|
+
# a non-Rackspace OpenStack Swift installation. Requires 1.4.11 or higher of the Cloud Files gem.
|
42
46
|
module Cloud_files
|
43
47
|
def self.extended base
|
44
48
|
require 'cloudfiles'
|
45
49
|
@@container ||= {}
|
46
50
|
base.instance_eval do
|
47
51
|
@cloudfiles_credentials = parse_credentials(@options[:cloudfiles_credentials])
|
48
|
-
@container_name = @options[:container]
|
52
|
+
@container_name = @options[:container] || options[:container_name] || @cloudfiles_credentials[:container] || @cloudfiles_credentials[:container_name]
|
49
53
|
@container_name = @container_name.call(self) if @container_name.is_a?(Proc)
|
50
54
|
@cloudfiles_options = @options[:cloudfiles_options] || {}
|
51
55
|
@@cdn_url = cloudfiles_container.cdn_url
|
@@ -59,7 +63,10 @@ module Paperclip
|
|
59
63
|
end
|
60
64
|
|
61
65
|
def cloudfiles
|
62
|
-
@@cf ||= CloudFiles::Connection.new(:username => @cloudfiles_credentials[:username],
|
66
|
+
@@cf ||= CloudFiles::Connection.new(:username => @cloudfiles_credentials[:username],
|
67
|
+
:api_key => @cloudfiles_credentials[:api_key],
|
68
|
+
:snet => @cloudfiles_credentials[:servicenet],
|
69
|
+
:auth_url => (@cloudfiles_credentials[:auth_url] || "https://auth.api.rackspacecloud.com/v1.0"))
|
63
70
|
end
|
64
71
|
|
65
72
|
def create_container
|
data/lib/paperclip/version.rb
CHANGED
data/test/integration_test.rb
CHANGED
@@ -34,6 +34,22 @@ class IntegrationTest < Test::Unit::TestCase
|
|
34
34
|
should "create its thumbnails properly" do
|
35
35
|
assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
|
36
36
|
end
|
37
|
+
|
38
|
+
context 'reprocessing with unreadable original' do
|
39
|
+
setup { File.chmod(0000, @dummy.avatar.path) }
|
40
|
+
|
41
|
+
should "not raise an error" do
|
42
|
+
assert_nothing_raised do
|
43
|
+
@dummy.avatar.reprocess!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
should "return false" do
|
48
|
+
assert ! @dummy.avatar.reprocess!
|
49
|
+
end
|
50
|
+
|
51
|
+
teardown { File.chmod(0644, @dummy.avatar.path) }
|
52
|
+
end
|
37
53
|
|
38
54
|
context "redefining its attachment styles" do
|
39
55
|
setup do
|
data/test/storage_test.rb
CHANGED
@@ -7,6 +7,29 @@ class StorageTest < Test::Unit::TestCase
|
|
7
7
|
Object.const_set(:Rails, stub('Rails', :env => env))
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
context "filesystem" do
|
12
|
+
setup do
|
13
|
+
rebuild_model :styles => { :thumbnail => "25x25#" }
|
14
|
+
@dummy = Dummy.create!
|
15
|
+
|
16
|
+
@dummy.avatar = File.open(File.join(File.dirname(__FILE__), "fixtures", "5k.png"))
|
17
|
+
end
|
18
|
+
|
19
|
+
should "allow file assignment" do
|
20
|
+
assert @dummy.save
|
21
|
+
end
|
22
|
+
|
23
|
+
should "store the original" do
|
24
|
+
@dummy.save
|
25
|
+
assert File.exists?(@dummy.avatar.path)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "store the thumbnail" do
|
29
|
+
@dummy.save
|
30
|
+
assert File.exists?(@dummy.avatar.path(:thumbnail))
|
31
|
+
end
|
32
|
+
end
|
10
33
|
|
11
34
|
context "Parsing S3 credentials" do
|
12
35
|
setup do
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-cloudfiles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 85
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
9
|
- 8
|
10
|
-
|
10
|
+
- 1
|
11
|
+
version: 2.3.8.1
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Jon Yurek
|
@@ -16,12 +17,13 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2011-
|
20
|
+
date: 2011-02-05 00:00:00 -05:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
23
24
|
prerelease: false
|
24
|
-
|
25
|
+
type: :runtime
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
27
|
none: false
|
26
28
|
requirements:
|
27
29
|
- - ">="
|
@@ -30,12 +32,12 @@ dependencies:
|
|
30
32
|
segments:
|
31
33
|
- 0
|
32
34
|
version: "0"
|
33
|
-
requirement: *id001
|
34
35
|
name: activerecord
|
35
|
-
|
36
|
+
version_requirements: *id001
|
36
37
|
- !ruby/object:Gem::Dependency
|
37
38
|
prerelease: false
|
38
|
-
|
39
|
+
type: :runtime
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
@@ -44,12 +46,12 @@ dependencies:
|
|
44
46
|
segments:
|
45
47
|
- 0
|
46
48
|
version: "0"
|
47
|
-
requirement: *id002
|
48
49
|
name: activesupport
|
49
|
-
|
50
|
+
version_requirements: *id002
|
50
51
|
- !ruby/object:Gem::Dependency
|
51
52
|
prerelease: false
|
52
|
-
|
53
|
+
type: :development
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
55
|
none: false
|
54
56
|
requirements:
|
55
57
|
- - ">="
|
@@ -58,12 +60,12 @@ dependencies:
|
|
58
60
|
segments:
|
59
61
|
- 0
|
60
62
|
version: "0"
|
61
|
-
requirement: *id003
|
62
63
|
name: shoulda
|
63
|
-
|
64
|
+
version_requirements: *id003
|
64
65
|
- !ruby/object:Gem::Dependency
|
65
66
|
prerelease: false
|
66
|
-
|
67
|
+
type: :development
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
69
|
none: false
|
68
70
|
requirements:
|
69
71
|
- - ">="
|
@@ -72,12 +74,12 @@ dependencies:
|
|
72
74
|
segments:
|
73
75
|
- 0
|
74
76
|
version: "0"
|
75
|
-
requirement: *id004
|
76
77
|
name: appraisal
|
77
|
-
|
78
|
+
version_requirements: *id004
|
78
79
|
- !ruby/object:Gem::Dependency
|
79
80
|
prerelease: false
|
80
|
-
|
81
|
+
type: :development
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
83
|
none: false
|
82
84
|
requirements:
|
83
85
|
- - ">="
|
@@ -86,12 +88,12 @@ dependencies:
|
|
86
88
|
segments:
|
87
89
|
- 0
|
88
90
|
version: "0"
|
89
|
-
requirement: *id005
|
90
91
|
name: mocha
|
91
|
-
|
92
|
+
version_requirements: *id005
|
92
93
|
- !ruby/object:Gem::Dependency
|
93
94
|
prerelease: false
|
94
|
-
|
95
|
+
type: :development
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
97
|
none: false
|
96
98
|
requirements:
|
97
99
|
- - ">="
|
@@ -100,12 +102,12 @@ dependencies:
|
|
100
102
|
segments:
|
101
103
|
- 0
|
102
104
|
version: "0"
|
103
|
-
requirement: *id006
|
104
105
|
name: aws-s3
|
105
|
-
|
106
|
+
version_requirements: *id006
|
106
107
|
- !ruby/object:Gem::Dependency
|
107
108
|
prerelease: false
|
108
|
-
|
109
|
+
type: :development
|
110
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
111
|
none: false
|
110
112
|
requirements:
|
111
113
|
- - ">="
|
@@ -116,12 +118,12 @@ dependencies:
|
|
116
118
|
- 4
|
117
119
|
- 9
|
118
120
|
version: 1.4.9
|
119
|
-
requirement: *id007
|
120
121
|
name: cloudfiles
|
121
|
-
|
122
|
+
version_requirements: *id007
|
122
123
|
- !ruby/object:Gem::Dependency
|
123
124
|
prerelease: false
|
124
|
-
|
125
|
+
type: :development
|
126
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
125
127
|
none: false
|
126
128
|
requirements:
|
127
129
|
- - ">="
|
@@ -130,9 +132,8 @@ dependencies:
|
|
130
132
|
segments:
|
131
133
|
- 0
|
132
134
|
version: "0"
|
133
|
-
requirement: *id008
|
134
135
|
name: sqlite3-ruby
|
135
|
-
|
136
|
+
version_requirements: *id008
|
136
137
|
description: Easy upload management for ActiveRecord with Rackspace Cloud Files support
|
137
138
|
email:
|
138
139
|
- jyurek@thoughtbot.com
|
@@ -142,9 +143,9 @@ executables: []
|
|
142
143
|
extensions: []
|
143
144
|
|
144
145
|
extra_rdoc_files:
|
145
|
-
- README.
|
146
|
+
- README.md
|
146
147
|
files:
|
147
|
-
- README.
|
148
|
+
- README.md
|
148
149
|
- LICENSE
|
149
150
|
- Rakefile
|
150
151
|
- init.rb
|
@@ -236,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
237
|
requirements:
|
237
238
|
- ImageMagick
|
238
239
|
rubyforge_project: paperclip
|
239
|
-
rubygems_version: 1.
|
240
|
+
rubygems_version: 1.5.0
|
240
241
|
signing_key:
|
241
242
|
specification_version: 3
|
242
243
|
summary: File attachments as attributes for ActiveRecord with Rackspace Cloud Files support
|