delayed_paperclip 2.10.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/Appraisals +1 -13
  4. data/README.md +41 -95
  5. data/delayed_paperclip.gemspec +7 -8
  6. data/gemfiles/5.0.gemfile +1 -1
  7. data/lib/delayed_paperclip.rb +3 -13
  8. data/lib/delayed_paperclip/process_job.rb +14 -0
  9. data/lib/delayed_paperclip/railtie.rb +10 -15
  10. data/lib/delayed_paperclip/version.rb +1 -1
  11. data/spec/delayed_paperclip/attachment_spec.rb +0 -1
  12. data/spec/delayed_paperclip/class_methods_spec.rb +0 -1
  13. data/spec/delayed_paperclip/instance_methods_spec.rb +0 -1
  14. data/spec/delayed_paperclip/url_generator_spec.rb +0 -1
  15. data/spec/delayed_paperclip_spec.rb +15 -22
  16. data/spec/integration/base_delayed_paperclip_spec.rb +0 -5
  17. data/spec/integration/examples/base.rb +6 -4
  18. data/spec/integration/process_job_spec.rb +26 -0
  19. data/spec/spec_helper.rb +7 -11
  20. metadata +22 -84
  21. data/gemfiles/3.2.gemfile +0 -7
  22. data/gemfiles/4.0.gemfile +0 -7
  23. data/gemfiles/4.1.gemfile +0 -7
  24. data/init.rb +0 -4
  25. data/lib/delayed_paperclip/jobs.rb +0 -8
  26. data/lib/delayed_paperclip/jobs/active_job.rb +0 -14
  27. data/lib/delayed_paperclip/jobs/delayed_job.rb +0 -46
  28. data/lib/delayed_paperclip/jobs/resque.rb +0 -22
  29. data/lib/delayed_paperclip/jobs/sidekiq.rb +0 -30
  30. data/rails/init.rb +0 -2
  31. data/spec/integration/active_job_inline_spec.rb +0 -26
  32. data/spec/integration/active_job_resque_spec.rb +0 -28
  33. data/spec/integration/active_job_sidekiq_spec.rb +0 -34
  34. data/spec/integration/delayed_job_spec.rb +0 -63
  35. data/spec/integration/resque_spec.rb +0 -47
  36. data/spec/integration/sidekiq_spec.rb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5ac9bcd09517a634af35fb347bdc11cf538bb20
4
- data.tar.gz: f11ca1ba331c50817bd6a9bcd3b6197948a4ae23
3
+ metadata.gz: 87f666e3339caae1a67262dc9d7a2e0a4735a4cb
4
+ data.tar.gz: 17312387a6ca724e835abee1b1aac059c28e24b2
5
5
  SHA512:
6
- metadata.gz: 3d297de920ba09991941b8a0d3c172c0a36cdc3a89542797eb9341ef757da42cf11a7f2176e985f74d13d93ae8aa2ce8b38ce3749833d789a8784e7c5a64a30f
7
- data.tar.gz: f8eb0f2c138883e8a948b6523d29ed18fb7c045b9d0e81020fc004e5e6b9c9b7fb4958e925abfd672c210a1fbd9a7309a49239856165657e25e311e88363255b
6
+ metadata.gz: cd54dd5bf121d9d9b1bec0feeb669d8afed6dbf0edecc4088f14c84578d976e2cab2e55e5959f03a3b6aba0ca6a75870285870938f6b156ee8bf8d1e0c0402d2
7
+ data.tar.gz: 5731d670649b7b293b587192d7f569912caf43c717c100b384e24bbc2377b297f30346edf69c88a7c5320621ee1d5a1c9221abedeb59ee8f40e2c81b9ef83558
data/.travis.yml CHANGED
@@ -9,19 +9,19 @@ rvm:
9
9
  - 2.0
10
10
 
11
11
  gemfile:
12
- - gemfiles/3.2.gemfile
13
- - gemfiles/4.0.gemfile
14
- - gemfiles/4.1.gemfile
15
12
  - gemfiles/4.2.gemfile
16
13
  - gemfiles/5.0.gemfile
17
14
 
18
- # Rails 5.0 requires Ruby >= 2.2
15
+ # Rails 5.0 requires Ruby >= 2.2.2
19
16
  matrix:
20
17
  exclude:
21
18
  - rvm: 2.1.10
22
19
  gemfile: gemfiles/5.0.gemfile
23
20
  - rvm: 2.0
24
21
  gemfile: gemfiles/5.0.gemfile
22
+ # Paperclip >= 5.0 requires Ruby 2.1
23
+ - rvm: 2.0
24
+ gemfile: gemfiles/4.2.gemfile
25
25
 
26
26
  script: "bundle exec rake clean spec"
27
27
 
data/Appraisals CHANGED
@@ -1,19 +1,7 @@
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
-
13
1
  appraise "4.2" do
14
2
  gem "rails", "~> 4.2.0"
15
3
  end
16
4
 
17
5
  appraise "5.0" do
18
- gem "rails", "~> 5.0.0.beta3"
6
+ gem "rails", "~> 5.0.0"
19
7
  end
data/README.md CHANGED
@@ -3,10 +3,7 @@ Delayed::Paperclip [![Build Status](https://travis-ci.org/jrgifford/delayed_pape
3
3
 
4
4
 
5
5
  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)
10
7
 
11
8
  Why?
12
9
  ----
@@ -14,8 +11,7 @@ Why?
14
11
  The most common use case for Paperclip is to easily attach image files
15
12
  to ActiveRecord models. Most of the time these image files will have
16
13
  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.
19
15
 
20
16
  I’m sure that everyone knows this, this gem just makes it easy to do.
21
17
 
@@ -24,28 +20,23 @@ Installation
24
20
 
25
21
  Install the gem:
26
22
 
27
- ````
23
+ ```
28
24
  gem install delayed_paperclip
29
- ````
25
+ ```
30
26
 
31
27
  Or even better, add it to your Gemfile.
32
28
 
33
- ````
29
+ ```
34
30
  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
+ ```
42
33
 
43
34
  Usage
44
35
  -----
45
36
 
46
37
  In your model:
47
38
 
48
- ````ruby
39
+ ```ruby
49
40
  class User < ActiveRecord::Base
50
41
  has_attached_file :avatar, styles: {
51
42
  medium: "300x300>",
@@ -54,57 +45,10 @@ class User < ActiveRecord::Base
54
45
 
55
46
  process_in_background :avatar
56
47
  end
57
- ````
48
+ ```
58
49
 
59
50
  Use your Paperclip attachment just like always in controllers and views.
60
51
 
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
-
108
52
  ### Displaying images during processing
109
53
 
110
54
  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
117
61
  `#{attachment_name}_processing` column to the specific model you want
118
62
  to enable this feature for. This feature gracefully degrades and will not affect models which do not have the column added to them.
119
63
 
120
- ````ruby
64
+ ```ruby
121
65
  class AddAvatarProcessingToUser < ActiveRecord::Migration
122
66
  def self.up
123
67
  add_column :users, :avatar_processing, :boolean
@@ -131,18 +75,19 @@ end
131
75
  @user = User.new(avatar: File.new(...))
132
76
  @user.save
133
77
  @user.avatar.url #=> "/images/original/missing.png"
134
- Delayed::Worker.new.work_off
78
+
79
+ # Process job
135
80
 
136
81
  @user.reload
137
82
  @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
138
- ````
83
+ ```
139
84
 
140
85
  #### Custom image for processing
141
86
 
142
87
  This is useful if you have a difference between missing images and
143
88
  images currently being processed.
144
89
 
145
- ````ruby
90
+ ```ruby
146
91
  class User < ActiveRecord::Base
147
92
  has_attached_file :avatar
148
93
 
@@ -152,17 +97,17 @@ end
152
97
  @user = User.new(avatar: File.new(...))
153
98
  @user.save
154
99
  @user.avatar.url #=> "/images/original/processing.png"
155
- Delayed::Worker.new.work_off
100
+
101
+ # Process job
156
102
 
157
103
  @user.reload
158
104
  @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
159
- ````
105
+ ```
160
106
 
161
107
  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.
164
109
 
165
- ````ruby
110
+ ```ruby
166
111
  class Item < ActiveRecord::Base
167
112
  has_attached_file :photo
168
113
 
@@ -173,7 +118,7 @@ class Item < ActiveRecord::Base
173
118
  options[:interpolator].interpolate(options[:url], photo, :original)
174
119
  end
175
120
  end
176
- ````
121
+ ```
177
122
 
178
123
  #### Have processing? status available, but construct image URLs as if delayed_paperclip wasn’t present
179
124
 
@@ -183,7 +128,7 @@ If you define the `#{attachment_name}_processing` column, but set the
183
128
  Note especially the method #processing? which passes through the value
184
129
  of the boolean created via migration.
185
130
 
186
- ````ruby
131
+ ```ruby
187
132
  class User < ActiveRecord::Base
188
133
  has_attached_file :avatar
189
134
 
@@ -194,36 +139,37 @@ end
194
139
  @user.save
195
140
  @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
196
141
  @user.avatar.processing? #=> true
197
- Delayed::Worker.new.work_off
142
+
143
+ # Process job
198
144
 
199
145
  @user.reload
200
146
  @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
201
147
  @user.avatar.processing? #=> false
202
- ````
148
+ ```
203
149
 
204
150
  #### Only process certain styles
205
151
 
206
152
  This is useful if you don’t want the background job to reprocess all
207
153
  styles.
208
154
 
209
- ````ruby
155
+ ```ruby
210
156
  class User < ActiveRecord::Base
211
157
  has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
212
158
 
213
159
  process_in_background :avatar, only_process: [:small]
214
160
  end
215
- ````
161
+ ```
216
162
 
217
163
  Like paperclip, you could also supply a lambda function to define
218
164
  `only_process` dynamically.
219
165
 
220
- ````ruby
166
+ ```ruby
221
167
  class User < ActiveRecord::Base
222
168
  has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
223
169
 
224
170
  process_in_background :avatar, only_process: lambda { |a| a.instance.small_supported? ? [:small, :large] : [:large] }
225
171
  end
226
- ````
172
+ ```
227
173
 
228
174
  #### Split processing
229
175
 
@@ -231,21 +177,21 @@ You can process some styles in the foreground and some in the background
231
177
  by setting `only_process` on both `has_attached_file` and
232
178
  `process_in_background`.
233
179
 
234
- ````ruby
180
+ ```ruby
235
181
  class User < ActiveRecord::Base
236
182
  has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }, only_process: [:small]
237
183
 
238
184
  process_in_background :avatar, only_process: [:medium]
239
185
  end
240
- ````
186
+ ```
241
187
 
242
188
  #### Reprocess Without Delay
243
189
 
244
190
  This is useful if you don’t want the background job. It accepts
245
- individual styles to. Take note, normal `reprocess!` does not accept styles as arguments anymore. It will delegate to DelayedPaperclip and
191
+ individual styles too. Take note, normal `reprocess!` does not accept styles as arguments anymore. It will delegate to DelayedPaperclip and
246
192
  reprocess all styles.
247
193
 
248
- ````ruby
194
+ ```ruby
249
195
  class User < ActiveRecord::Base
250
196
  has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
251
197
 
@@ -254,7 +200,7 @@ end
254
200
 
255
201
  @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
256
202
  @user.avatar.reprocess_without_delay!(:medium)
257
- ````
203
+ ```
258
204
 
259
205
  #### Set queue name
260
206
 
@@ -278,7 +224,7 @@ defined by changing the DelayedPaperclip.options Hash, this can be useful for se
278
224
  If you’re using Rails you can define a Hash with default options in
279
225
  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:
280
226
 
281
- ````ruby
227
+ ```ruby
282
228
  module YourApp
283
229
  class Application < Rails::Application
284
230
  # Other code...
@@ -289,7 +235,7 @@ module YourApp
289
235
  }
290
236
  end
291
237
  end
292
- ````
238
+ ```
293
239
 
294
240
  What if I’m not using images?
295
241
  -----------------------------
@@ -301,7 +247,7 @@ Paperclip Post-processors are not working
301
247
  -----------------------------------------
302
248
 
303
249
  If you are using custom [post-processing processors](https://github.com/thoughtbot/paperclip#post-processing)
304
- like this:
250
+ like this:
305
251
 
306
252
  ```ruby
307
253
  # ...
@@ -311,14 +257,14 @@ process_in_background :avatar
311
257
 
312
258
  def rotate!
313
259
  # ...
314
- avatar.reprocess!
260
+ avatar.reprocess!
315
261
  # ...
316
262
  end
317
263
 
318
264
  # ...
319
265
  ```
320
266
 
321
- ...you may encounter an issue where your post-processors are ignored
267
+ ...you may encounter an issue where your post-processors are ignored
322
268
  ([more info](https://github.com/jrgifford/delayed_paperclip/issues/171)).
323
269
  In order to avoid this use `reprocess_without_delay!`
324
270
 
@@ -327,7 +273,7 @@ In order to avoid this use `reprocess_without_delay!`
327
273
 
328
274
  def rotate!
329
275
  # ...
330
- avatar.reprocess_without_delay!
276
+ avatar.reprocess_without_delay!
331
277
  # ...
332
278
  end
333
279
 
@@ -344,7 +290,7 @@ Contributing
344
290
 
345
291
  Checkout out [CONTRIBUTING](https://github.com/jrgifford/delayed_paperclip/blob/master/CONTRIBUTING). Run specs with:
346
292
 
347
- ````
293
+ ```
348
294
  # Rspec on all versions
349
295
  bundle exec appraisal install
350
296
  bundle exec appraisal rake
@@ -354,4 +300,4 @@ bundle exec rake
354
300
 
355
301
  # Rspec on specific rails version
356
302
  bundle exec appraisal 5.0 rake
357
- ````
303
+ ```
@@ -6,25 +6,24 @@ Gem::Specification.new do |s|
6
6
  s.version = DelayedPaperclip::VERSION
7
7
 
8
8
  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}
11
11
  s.email = %w{james@jamesrgifford.com scott@artsicle.com}
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"
13
15
 
14
16
  s.add_dependency 'paperclip', [">= 3.3"]
17
+ s.add_dependency 'activejob', ">= 4.2"
15
18
 
16
19
  s.add_development_dependency 'mocha'
17
20
  s.add_development_dependency "rspec", '< 3.0'
18
21
  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'
23
22
  s.add_development_dependency 'appraisal'
24
23
  s.add_development_dependency 'rake', '~> 10.5.0'
25
24
  s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'activerecord'
26
26
  s.add_development_dependency 'railties'
27
- s.add_development_dependency 'fakeredis'
28
27
 
29
28
  s.files = `git ls-files`.split("\n")
30
29
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/gemfiles/5.0.gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "http://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.0.beta3"
5
+ gem "rails", "~> 5.0.0"
6
6
 
7
7
  gemspec :path => "../"
@@ -1,28 +1,19 @@
1
- require 'delayed_paperclip/jobs'
1
+ require 'delayed_paperclip/process_job'
2
2
  require 'delayed_paperclip/attachment'
3
3
  require 'delayed_paperclip/url_generator'
4
- require 'delayed_paperclip/railtie'
4
+ require 'delayed_paperclip/railtie' if defined?(Rails)
5
5
 
6
6
  module DelayedPaperclip
7
-
8
7
  class << self
9
-
10
8
  def options
11
9
  @options ||= {
12
- :background_job_class => detect_background_task,
10
+ :background_job_class => DelayedPaperclip::ProcessJob,
13
11
  :url_with_processing => true,
14
12
  :processing_image_url => nil,
15
13
  :queue => "paperclip"
16
14
  }
17
15
  end
18
16
 
19
- def detect_background_task
20
- return DelayedPaperclip::Jobs::ActiveJob if defined? ::ActiveJob::Base
21
- return DelayedPaperclip::Jobs::DelayedJob if defined? ::Delayed::Job
22
- return DelayedPaperclip::Jobs::Resque if defined? ::Resque
23
- return DelayedPaperclip::Jobs::Sidekiq if defined? ::Sidekiq
24
- end
25
-
26
17
  def processor
27
18
  options[:background_job_class]
28
19
  end
@@ -120,6 +111,5 @@ module DelayedPaperclip
120
111
  @_enqued_for_processing ||= []
121
112
  @_enqued_for_processing << name
122
113
  end
123
-
124
114
  end
125
115
  end