Skip to content
This repository was archived by the owner on Oct 5, 2018. It is now read-only.

Commit 5acccb4

Browse files
author
Scott Carleton
authored
Merge pull request #184 from jrgifford/3-0
Get ready for 3.0
2 parents 5ff4b8a + 8015cf5 commit 5acccb4

32 files changed

+129
-591
lines changed

.travis.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ rvm:
99
- 2.0
1010

1111
gemfile:
12-
- gemfiles/3.2.gemfile
13-
- gemfiles/4.0.gemfile
14-
- gemfiles/4.1.gemfile
1512
- gemfiles/4.2.gemfile
1613
- gemfiles/5.0.gemfile
1714

18-
# Rails 5.0 requires Ruby >= 2.2
15+
# Rails 5.0 requires Ruby >= 2.2.2
1916
matrix:
2017
exclude:
2118
- rvm: 2.1.10

Appraisals

-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
appraise "3.2" do
2-
gem "rails", "~> 3.2.15"
3-
end
4-
5-
appraise "4.0" do
6-
gem "rails", "~> 4.0.0"
7-
end
8-
9-
appraise "4.1" do
10-
gem "rails", "~> 4.1.0"
11-
end
12-
131
appraise "4.2" do
142
gem "rails", "~> 4.2.0"
153
end

README.md

+40-94
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ Delayed::Paperclip [![Build Status](https://travis-ci.org/jrgifford/delayed_pape
33

44

55
DelayedPaperclip lets you process your [Paperclip](http://github.com/thoughtbot/paperclip)
6-
attachments in a background task with
7-
[ActiveJob](https://github.com/rails/rails/tree/master/activejob),
8-
[DelayedJob](https://github.com/collectiveidea/delayed_job),
9-
[Resque](https://github.com/resque/resque) or [Sidekiq](https://github.com/mperham/sidekiq).
6+
attachments in a background task with [ActiveJob](https://github.com/rails/rails/tree/master/activejob)
107

118
Why?
129
----
1310

1411
The most common use case for Paperclip is to easily attach image files
1512
to ActiveRecord models. Most of the time these image files will have
1613
multiple styles and will need to be resized when they are created. This
17-
is usually a pretty [slow operation](http://www.jstorimer.com/ruby/2010/01/05/speep-up-your-paperclip-tests.html) and should be handled in a
18-
background task.
14+
is usually a pretty slow operation and should be handled in a background task.
1915

2016
I’m sure that everyone knows this, this gem just makes it easy to do.
2117

@@ -24,28 +20,23 @@ Installation
2420

2521
Install the gem:
2622

27-
````
23+
```
2824
gem install delayed_paperclip
29-
````
25+
```
3026

3127
Or even better, add it to your Gemfile.
3228

33-
````
29+
```
3430
source "https://rubygems.org"
35-
gem 'delayed_paperclip'
36-
````
37-
38-
Dependencies:
39-
40-
- Paperclip
41-
- DJ, Resque or Sidekiq
31+
gem "delayed_paperclip"
32+
```
4233

4334
Usage
4435
-----
4536

4637
In your model:
4738

48-
````ruby
39+
```ruby
4940
class User < ActiveRecord::Base
5041
has_attached_file :avatar, styles: {
5142
medium: "300x300>",
@@ -54,57 +45,10 @@ class User < ActiveRecord::Base
5445

5546
process_in_background :avatar
5647
end
57-
````
48+
```
5849

5950
Use your Paperclip attachment just like always in controllers and views.
6051

61-
To select between using Resque or Delayed::Job, just install and
62-
configure your choice properly within your application, and
63-
delayed_paperclip will do the rest. It will detect which library is
64-
loaded and make a decision about which sort of job to enqueue at that
65-
time.
66-
67-
### Active Job
68-
69-
[Active Job](https://github.com/rails/rails/tree/master/activejob) will take
70-
precedence over any other installed library. Since it is installed as a
71-
dependency with Rails 4.2.1 this might cause some confusion, so make sure that
72-
Active Job is configured to use the correct queue adapter:
73-
74-
````ruby
75-
module YourApp
76-
class Application < Rails::Application
77-
# Other code...
78-
79-
config.active_job.queue_adapter = :resque # Or :delayed_job or :sidekiq
80-
end
81-
end
82-
````
83-
84-
### Resque
85-
86-
Resque adapter is deprecated. Please use ActiveJob one.
87-
88-
Make sure that you have [Resque](https://github.com/resque/resque) up and running. The jobs will be
89-
dispatched to the <code>:paperclip</code> queue, so you can correctly
90-
dispatch your worker. Configure resque and your workers exactly as you
91-
would otherwise.
92-
93-
### DJ
94-
95-
DelayedJob adapter is deprecated. Please use ActiveJob one.
96-
97-
Just make sure that you have DJ up and running.
98-
99-
### Sidekiq
100-
101-
Sidekiq adapter is deprecated. Please use ActiveJob one.
102-
103-
Make sure that [Sidekiq](http://github.com/mperham/sidekiq) is running and listening to the
104-
`paperclip` queue, either by adding it to your
105-
`sidekiq.yml` config file under `- queues:` or by
106-
passing the command line argument `-q paperclip` to Sidekiq.
107-
10852
### Displaying images during processing
10953

11054
In the default setup, when you upload an image for the first time and
@@ -117,7 +61,7 @@ To have the missing image url be outputted by paperclip while the image is being
11761
`#{attachment_name}_processing` column to the specific model you want
11862
to enable this feature for. This feature gracefully degrades and will not affect models which do not have the column added to them.
11963

120-
````ruby
64+
```ruby
12165
class AddAvatarProcessingToUser < ActiveRecord::Migration
12266
def self.up
12367
add_column :users, :avatar_processing, :boolean
@@ -131,18 +75,19 @@ end
13175
@user = User.new(avatar: File.new(...))
13276
@user.save
13377
@user.avatar.url #=> "/images/original/missing.png"
134-
Delayed::Worker.new.work_off
78+
79+
# Process job
13580

13681
@user.reload
13782
@user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
138-
````
83+
```
13984

14085
#### Custom image for processing
14186

14287
This is useful if you have a difference between missing images and
14388
images currently being processed.
14489

145-
````ruby
90+
```ruby
14691
class User < ActiveRecord::Base
14792
has_attached_file :avatar
14893

@@ -152,17 +97,17 @@ end
15297
@user = User.new(avatar: File.new(...))
15398
@user.save
15499
@user.avatar.url #=> "/images/original/processing.png"
155-
Delayed::Worker.new.work_off
100+
101+
# Process job
156102

157103
@user.reload
158104
@user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
159-
````
105+
```
160106

161107
You can also define a custom logic for `processing_image_url`, for
162-
example to display the original\
163-
picture while specific formats are being processed.
108+
example to display the original picture while specific formats are being processed.
164109

165-
````ruby
110+
```ruby
166111
class Item < ActiveRecord::Base
167112
has_attached_file :photo
168113

@@ -173,7 +118,7 @@ class Item < ActiveRecord::Base
173118
options[:interpolator].interpolate(options[:url], photo, :original)
174119
end
175120
end
176-
````
121+
```
177122

178123
#### Have processing? status available, but construct image URLs as if delayed_paperclip wasn’t present
179124

@@ -183,7 +128,7 @@ If you define the `#{attachment_name}_processing` column, but set the
183128
Note especially the method #processing? which passes through the value
184129
of the boolean created via migration.
185130

186-
````ruby
131+
```ruby
187132
class User < ActiveRecord::Base
188133
has_attached_file :avatar
189134

@@ -194,58 +139,59 @@ end
194139
@user.save
195140
@user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
196141
@user.avatar.processing? #=> true
197-
Delayed::Worker.new.work_off
142+
143+
# Process job
198144

199145
@user.reload
200146
@user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
201147
@user.avatar.processing? #=> false
202-
````
148+
```
203149

204150
#### Only process certain styles
205151

206152
This is useful if you don’t want the background job to reprocess all
207153
styles.
208154

209-
````ruby
155+
```ruby
210156
class User < ActiveRecord::Base
211157
has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
212158

213159
process_in_background :avatar, only_process: [:small]
214160
end
215-
````
161+
```
216162

217163
Like paperclip, you could also supply a lambda function to define
218164
`only_process` dynamically.
219165

220-
````ruby
166+
```ruby
221167
class User < ActiveRecord::Base
222168
has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
223169

224170
process_in_background :avatar, only_process: lambda { |a| a.instance.small_supported? ? [:small, :large] : [:large] }
225171
end
226-
````
172+
```
227173

228174
#### Split processing
229175

230176
You can process some styles in the foreground and some in the background
231177
by setting `only_process` on both `has_attached_file` and
232178
`process_in_background`.
233179

234-
````ruby
180+
```ruby
235181
class User < ActiveRecord::Base
236182
has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }, only_process: [:small]
237183

238184
process_in_background :avatar, only_process: [:medium]
239185
end
240-
````
186+
```
241187

242188
#### Reprocess Without Delay
243189

244190
This is useful if you don’t want the background job. It accepts
245191
individual styles too. Take note, normal `reprocess!` does not accept styles as arguments anymore. It will delegate to DelayedPaperclip and
246192
reprocess all styles.
247193

248-
````ruby
194+
```ruby
249195
class User < ActiveRecord::Base
250196
has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
251197

@@ -254,7 +200,7 @@ end
254200

255201
@user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
256202
@user.avatar.reprocess_without_delay!(:medium)
257-
````
203+
```
258204

259205
#### Set queue name
260206

@@ -278,7 +224,7 @@ defined by changing the DelayedPaperclip.options Hash, this can be useful for se
278224
If you’re using Rails you can define a Hash with default options in
279225
config/application.rb or in any of the config/environments/\*.rb files on `config.delayed_paperclip_defaults`, these will get merged into DelayedPaperclip.options as your Rails app boots. An example:
280226

281-
````ruby
227+
```ruby
282228
module YourApp
283229
class Application < Rails::Application
284230
# Other code...
@@ -289,7 +235,7 @@ module YourApp
289235
}
290236
end
291237
end
292-
````
238+
```
293239

294240
What if I’m not using images?
295241
-----------------------------
@@ -301,7 +247,7 @@ Paperclip Post-processors are not working
301247
-----------------------------------------
302248

303249
If you are using custom [post-processing processors](https://github.com/thoughtbot/paperclip#post-processing)
304-
like this:
250+
like this:
305251

306252
```ruby
307253
# ...
@@ -311,14 +257,14 @@ process_in_background :avatar
311257

312258
def rotate!
313259
# ...
314-
avatar.reprocess!
260+
avatar.reprocess!
315261
# ...
316262
end
317263

318264
# ...
319265
```
320266

321-
...you may encounter an issue where your post-processors are ignored
267+
...you may encounter an issue where your post-processors are ignored
322268
([more info](https://github.com/jrgifford/delayed_paperclip/issues/171)).
323269
In order to avoid this use `reprocess_without_delay!`
324270

@@ -327,7 +273,7 @@ In order to avoid this use `reprocess_without_delay!`
327273

328274
def rotate!
329275
# ...
330-
avatar.reprocess_without_delay!
276+
avatar.reprocess_without_delay!
331277
# ...
332278
end
333279

@@ -344,7 +290,7 @@ Contributing
344290

345291
Checkout out [CONTRIBUTING](https://github.com/jrgifford/delayed_paperclip/blob/master/CONTRIBUTING). Run specs with:
346292

347-
````
293+
```
348294
# Rspec on all versions
349295
bundle exec appraisal install
350296
bundle exec appraisal rake
@@ -354,4 +300,4 @@ bundle exec rake
354300
355301
# Rspec on specific rails version
356302
bundle exec appraisal 5.0 rake
357-
````
303+
```

delayed_paperclip.gemspec

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,24 @@ Gem::Specification.new do |s|
66
s.version = DelayedPaperclip::VERSION
77

88
s.authors = ["Jesse Storimer", "Bert Goethals", "James Gifford", "Scott Carleton"]
9-
s.summary = %q{Process your Paperclip attachments in the background.}
10-
s.description = %q{Process your Paperclip attachments in the background with DelayedJob, Resque, Sidekiq or your own processor.}
9+
s.summary = %q{Process your Paperclip attachments in the background}
10+
s.description = %q{Process your Paperclip attachments in the background with ActiveJob}
1111
12-
s.homepage = %q{http://github.com/jrgifford/delayed_paperclip}
12+
s.homepage = %q{https://github.com/jrgifford/delayed_paperclip}
13+
14+
s.required_ruby_version = ">= 2.0.0"
1315

1416
s.add_dependency 'paperclip', [">= 3.3"]
17+
s.add_dependency 'activejob', ">= 4.2"
1518

1619
s.add_development_dependency 'mocha'
1720
s.add_development_dependency "rspec", '< 3.0'
1821
s.add_development_dependency 'sqlite3'
19-
s.add_development_dependency 'delayed_job'
20-
s.add_development_dependency 'delayed_job_active_record'
21-
s.add_development_dependency 'resque'
22-
s.add_development_dependency 'sidekiq', '>= 4.0'
2322
s.add_development_dependency 'appraisal'
2423
s.add_development_dependency 'rake', '~> 10.5.0'
2524
s.add_development_dependency 'bundler'
25+
s.add_development_dependency 'activerecord'
2626
s.add_development_dependency 'railties'
27-
s.add_development_dependency 'fakeredis'
2827

2928
s.files = `git ls-files`.split("\n")
3029
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

0 commit comments

Comments
 (0)