delayed_paperclip 2.9.1 → 2.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.travis.yml +5 -6
  4. data/Appraisals +1 -5
  5. data/CONTRIBUTING +0 -3
  6. data/README.md +43 -11
  7. data/Rakefile +0 -13
  8. data/delayed_paperclip.gemspec +3 -3
  9. data/gemfiles/3.2.gemfile +0 -1
  10. data/gemfiles/4.0.gemfile +0 -1
  11. data/gemfiles/4.1.gemfile +0 -1
  12. data/gemfiles/4.2.gemfile +0 -1
  13. data/lib/delayed_paperclip.rb +6 -7
  14. data/lib/delayed_paperclip/attachment.rb +12 -6
  15. data/lib/delayed_paperclip/jobs/active_job.rb +3 -5
  16. data/lib/delayed_paperclip/jobs/delayed_job.rb +3 -2
  17. data/lib/delayed_paperclip/jobs/resque.rb +2 -3
  18. data/lib/delayed_paperclip/jobs/sidekiq.rb +7 -1
  19. data/lib/delayed_paperclip/railtie.rb +1 -1
  20. data/lib/delayed_paperclip/url_generator.rb +19 -25
  21. data/lib/delayed_paperclip/version.rb +1 -1
  22. data/spec/delayed_paperclip/attachment_spec.rb +98 -26
  23. data/spec/delayed_paperclip/class_methods_spec.rb +20 -12
  24. data/spec/delayed_paperclip/instance_methods_spec.rb +8 -12
  25. data/spec/delayed_paperclip/url_generator_spec.rb +24 -24
  26. data/spec/delayed_paperclip_spec.rb +37 -22
  27. data/spec/integration/active_job_inline_spec.rb +3 -3
  28. data/spec/integration/active_job_resque_spec.rb +4 -7
  29. data/spec/integration/active_job_sidekiq_spec.rb +17 -18
  30. data/spec/integration/base_delayed_paperclip_spec.rb +5 -6
  31. data/spec/integration/delayed_job_spec.rb +3 -4
  32. data/spec/integration/examples/base.rb +33 -25
  33. data/spec/integration/resque_spec.rb +4 -6
  34. data/spec/integration/sidekiq_spec.rb +8 -11
  35. data/spec/spec_helper.rb +15 -0
  36. metadata +23 -19
  37. data/gemfiles/3.2.gemfile.lock +0 -162
  38. data/gemfiles/4.0.gemfile.lock +0 -156
  39. data/gemfiles/4.1.gemfile.lock +0 -156
  40. data/gemfiles/4.2.gemfile.lock +0 -181
  41. data/test/base_delayed_paperclip_test.rb +0 -254
  42. data/test/database.yml +0 -4
  43. data/test/test_helper.rb +0 -106
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41fd7daaa3126fd153f1448405465ab92d983833
4
- data.tar.gz: 5953ed040cea15002ca58e269dd9b12eace3ed9c
3
+ metadata.gz: 6cd279c1d4024765a17e736762beaf90e355ae5c
4
+ data.tar.gz: abc9e943e6dbfd164e749edda10ae93847b80bd0
5
5
  SHA512:
6
- metadata.gz: 0558c10976a587d713e68e4b22f3bbfe0d5cbeaf84abad212d510b282bc0e33918dd3e3a98c60b5d05c56efd2e0a5a6255b35346214c0a9acb4d310a8e4bea3f
7
- data.tar.gz: c0db6281bbf54e20ef7489ae2ae094809471ad2d8fccc5578d8a52f00b507d49f6d37dbf148adfc82887a6a15a602a30f8b8d9062480ed56891cac0450d0c40b
6
+ metadata.gz: d8a46607f55622cc639ba1b94af952afa5d69bff67add0634789f681708ddd3b92b93a6f2b9b7fe8561dd7dbd9fb8d8838ff6cd239085bc7311026bfb92ea601
7
+ data.tar.gz: d9fcbafdcda62b4ebdf627f8a3a43ffda2397bf8e1e7fe09ff383ba0dde7b34a4499658f24d31ee90b475845670de522bb2a2623633b582dd30218c4a7c79382
data/.gitignore CHANGED
@@ -4,6 +4,6 @@ pkg/
4
4
  public/
5
5
  Gemfile.lock
6
6
  *.gem
7
- ./gemfiles/rails*.lock
7
+ gemfiles/*.lock
8
8
  .ruby-gemset
9
- .ruby-version
9
+ .ruby-version
@@ -1,6 +1,10 @@
1
1
  language: ruby
2
+ cache: bundler
3
+ sudo: false
2
4
 
3
5
  rvm:
6
+ - 2.3.0
7
+ - 2.2
4
8
  - 2.1
5
9
  - 2.0
6
10
 
@@ -8,11 +12,7 @@ gemfile:
8
12
  - gemfiles/3.2.gemfile
9
13
  - gemfiles/4.0.gemfile
10
14
  - gemfiles/4.1.gemfile
11
-
12
- sudo: false
13
-
14
- services:
15
- - redis
15
+ - gemfiles/4.2.gemfile
16
16
 
17
17
  script: "bundle exec rake clean spec"
18
18
 
@@ -20,4 +20,3 @@ notifications:
20
20
  email:
21
21
  - james@jamesrgifford.com
22
22
  - scott@artsicle.com
23
-
data/Appraisals CHANGED
@@ -1,19 +1,15 @@
1
1
  appraise "3.2" do
2
2
  gem "rails", "~> 3.2.15"
3
- gem "delayed_paperclip", path: "../"
4
3
  end
5
4
 
6
5
  appraise "4.0" do
7
6
  gem "rails", "~> 4.0.0"
8
- gem "delayed_paperclip", path: "../"
9
7
  end
10
8
 
11
9
  appraise "4.1" do
12
10
  gem "rails", "~> 4.1.0"
13
- gem "delayed_paperclip", path: "../"
14
11
  end
15
12
 
16
13
  appraise "4.2" do
17
14
  gem "rails", "~> 4.2.0"
18
- gem "delayed_paperclip", path: "../"
19
- end
15
+ end
@@ -8,9 +8,6 @@ Testing
8
8
 
9
9
  Please don't commit code without tests. You can bootstrap the development environment by running `bundle install`. After that, running `rake` should just work. If it doesn't then file a bug.
10
10
 
11
- Dependencies for Testing:
12
- - Redis. You need redis. For linux users, you can install the redis-server package and roll, Mac users will need to install it with homebrew, and I'm not entirely sure how to make it work with Windows users.
13
-
14
11
  Versioning
15
12
  =========
16
13
 
data/README.md CHANGED
@@ -2,8 +2,11 @@ Delayed::Paperclip [![Build Status](https://travis-ci.org/jrgifford/delayed_pape
2
2
  ======================================================================================
3
3
 
4
4
 
5
- DelayedPaperclip lets you process your [Paperclip](http://github.com/thoughtbot/paperclip) attachments in a
6
- background task with [DelayedJob](https://github.com/collectiveidea/delayed_job), [Resque](https://github.com/resque/resque) or [Sidekiq](https://github.com/mperham/sidekiq).
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).
7
10
 
8
11
  Why?
9
12
  ----
@@ -61,6 +64,23 @@ delayed_paperclip will do the rest. It will detect which library is
61
64
  loaded and make a decision about which sort of job to enqueue at that
62
65
  time.
63
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
+
64
84
  ### Resque
65
85
 
66
86
  Make sure that you have [Resque](https://github.com/resque/resque) up and running. The jobs will be
@@ -120,7 +140,7 @@ images currently being processed.
120
140
  class User < ActiveRecord::Base
121
141
  has_attached_file :avatar
122
142
 
123
- process_in_background :avatar, processing_image_url: "/images/original/processing.jpg"
143
+ process_in_background :avatar, processing_image_url: "/images/:style/processing.jpg"
124
144
  end
125
145
 
126
146
  @user = User.new(avatar: File.new(...))
@@ -182,7 +202,7 @@ styles.
182
202
 
183
203
  ````ruby
184
204
  class User < ActiveRecord::Base
185
- has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50x" }
205
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
186
206
 
187
207
  process_in_background :avatar, only_process: [:small]
188
208
  end
@@ -193,7 +213,7 @@ Like paperclip, you could also supply a lambda function to define
193
213
 
194
214
  ````ruby
195
215
  class User < ActiveRecord::Base
196
- has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50x" }
216
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
197
217
 
198
218
  process_in_background :avatar, only_process: lambda { |a| a.instance.small_supported? ? [:small, :large] : [:large] }
199
219
  end
@@ -207,7 +227,7 @@ by setting `only_process` on both `has_attached_file` and
207
227
 
208
228
  ````ruby
209
229
  class User < ActiveRecord::Base
210
- has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50x" }, only_process: [:small]
230
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }, only_process: [:small]
211
231
 
212
232
  process_in_background :avatar, only_process: [:medium]
213
233
  end
@@ -221,7 +241,7 @@ reprocess all styles.
221
241
 
222
242
  ````ruby
223
243
  class User < ActiveRecord::Base
224
- has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50x" }
244
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
225
245
 
226
246
  process_in_background :avatar
227
247
  end
@@ -230,6 +250,19 @@ end
230
250
  @user.avatar.reprocess_without_delay!(:medium)
231
251
  ````
232
252
 
253
+ #### Set queue name
254
+
255
+ You can set queue name for background job. By default it's called "paperclip".
256
+ You can set it by changing global default options or by:
257
+
258
+ ```
259
+ class User < ActiveRecord::Base
260
+ has_attached_file :avatar
261
+
262
+ process_in_background :avatar, queue: "default"
263
+ end
264
+ ```
265
+
233
266
  Defaults
234
267
  --------
235
268
 
@@ -239,7 +272,7 @@ defined by changing the DelayedPaperclip.options Hash, this can be useful for se
239
272
  If you’re using Rails you can define a Hash with default options in
240
273
  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:
241
274
 
242
- ````
275
+ ````ruby
243
276
  module YourApp
244
277
  class Application < Rails::Application
245
278
  # Other code...
@@ -266,10 +299,9 @@ Yes.
266
299
  Contributing
267
300
  ------------
268
301
 
269
- Checkout out CONTRIBUTING. In short, you’ll need a redis server running
270
- for testing. Run all tests with
302
+ Checkout out CONTRIBUTING. Run all tests with
271
303
 
272
304
  ````
273
305
  # Rspec on all versions
274
306
  rake appraisal spec
275
- ````
307
+ ````
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
2
 
4
3
  require 'appraisal'
@@ -6,8 +5,6 @@ require 'appraisal'
6
5
  require 'rake'
7
6
  require 'rake/testtask'
8
7
 
9
- $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
10
-
11
8
  desc 'Default: run unit tests.'
12
9
  task default: [:clean, 'appraisal:install', :all]
13
10
 
@@ -22,20 +19,10 @@ task :clean do |t|
22
19
  FileUtils.rm_rf "tmp"
23
20
  FileUtils.rm_rf "pkg"
24
21
  FileUtils.rm_rf "public"
25
- FileUtils.rm "test/debug.log" rescue nil
26
- FileUtils.rm "test/paperclip.db" rescue nil
27
22
  Dir.glob("paperclip-*.gem").each{|f| FileUtils.rm f }
28
23
  end
29
24
 
30
- desc 'Test the paperclip plugin.'
31
- Rake::TestTask.new(:test) do |t|
32
- t.libs << 'lib:test'
33
- t.pattern = 'test/**/*_test.rb'
34
- t.verbose = true
35
- end
36
-
37
25
  require 'rspec/core/rake_task'
38
26
  RSpec::Core::RakeTask.new do |t|
39
27
  t.pattern = 'spec/**/*_spec.rb'
40
28
  end
41
-
@@ -19,13 +19,13 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency 'delayed_job'
20
20
  s.add_development_dependency 'delayed_job_active_record'
21
21
  s.add_development_dependency 'resque'
22
- s.add_development_dependency 'sidekiq', '< 3.0'
22
+ s.add_development_dependency 'sidekiq', '>= 4.0'
23
23
  s.add_development_dependency 'appraisal'
24
- s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rake', '~> 10.5.0'
25
25
  s.add_development_dependency 'bundler'
26
26
  s.add_development_dependency 'railties'
27
+ s.add_development_dependency 'fakeredis'
27
28
 
28
29
  s.files = `git ls-files`.split("\n")
29
30
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
31
  end
31
-
@@ -3,6 +3,5 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 3.2.15"
6
- gem "delayed_paperclip", :path => "../"
7
6
 
8
7
  gemspec :path => "../"
@@ -3,6 +3,5 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.0.0"
6
- gem "delayed_paperclip", :path => "../"
7
6
 
8
7
  gemspec :path => "../"
@@ -3,6 +3,5 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.1.0"
6
- gem "delayed_paperclip", :path => "../"
7
6
 
8
7
  gemspec :path => "../"
@@ -3,6 +3,5 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
- gem "delayed_paperclip", :path => "../"
7
6
 
8
7
  gemspec :path => "../"
@@ -11,7 +11,8 @@ module DelayedPaperclip
11
11
  @options ||= {
12
12
  :background_job_class => detect_background_task,
13
13
  :url_with_processing => true,
14
- :processing_image_url => nil
14
+ :processing_image_url => nil,
15
+ :queue => "paperclip"
15
16
  }
16
17
  end
17
18
 
@@ -31,9 +32,9 @@ module DelayedPaperclip
31
32
  end
32
33
 
33
34
  def process_job(instance_klass, instance_id, attachment_name)
34
- instance_klass.constantize.unscoped.find(instance_id).
35
- send(attachment_name).
36
- process_delayed!
35
+ if instance = instance_klass.constantize.unscoped.where(id: instance_id).first
36
+ instance.send(attachment_name).process_delayed!
37
+ end
37
38
  end
38
39
 
39
40
  end
@@ -59,11 +60,9 @@ module DelayedPaperclip
59
60
  :only_process => only_process_default,
60
61
  :url_with_processing => DelayedPaperclip.options[:url_with_processing],
61
62
  :processing_image_url => DelayedPaperclip.options[:processing_image_url],
62
- :queue => nil
63
+ :queue => DelayedPaperclip.options[:queue]
63
64
  }.each do |option, default|
64
-
65
65
  paperclip_definitions[name][:delayed][option] = options.key?(option) ? options[option] : default
66
-
67
66
  end
68
67
 
69
68
  # Sets callback
@@ -4,9 +4,15 @@ module DelayedPaperclip
4
4
  def self.included(base)
5
5
  base.send :include, InstanceMethods
6
6
  base.send :attr_accessor, :job_is_processing
7
- base.alias_method_chain :post_processing, :delay
8
- base.alias_method_chain :post_processing=, :delay
9
- base.alias_method_chain :save, :prepare_enqueueing
7
+
8
+ base.send :alias_method, :post_processing_without_delay, :post_processing
9
+ base.send :alias_method, :post_processing, :post_processing_with_delay
10
+
11
+ base.send :alias_method, :post_processing_without_delay=, :post_processing=
12
+ base.send :alias_method, :post_processing=, :post_processing_with_delay=
13
+
14
+ base.send :alias_method, :save_without_prepare_enqueueing, :save
15
+ base.send :alias_method, :save, :save_with_prepare_enqueueing
10
16
  end
11
17
 
12
18
  module InstanceMethods
@@ -36,7 +42,7 @@ module DelayedPaperclip
36
42
 
37
43
  def split_processing?
38
44
  options[:only_process] && delayed_options &&
39
- options[:only_process] != delayed_options[:only_process]
45
+ options[:only_process] != delayed_only_process
40
46
  end
41
47
 
42
48
  def processing?
@@ -47,11 +53,11 @@ module DelayedPaperclip
47
53
  def processing_style?(style)
48
54
  return false if !processing?
49
55
 
50
- !split_processing? || delayed_options[:only_process].include?(style)
56
+ !split_processing? || delayed_only_process.include?(style)
51
57
  end
52
58
 
53
59
  def delayed_only_process
54
- only_process = delayed_options[:only_process].dup
60
+ only_process = delayed_options.fetch(:only_process, []).dup
55
61
  only_process = only_process.call(self) if only_process.respond_to?(:call)
56
62
  only_process.map(&:to_sym)
57
63
  end
@@ -1,11 +1,9 @@
1
1
  module DelayedPaperclip
2
2
  module Jobs
3
3
  class ActiveJob < ActiveJob::Base
4
- queue_as :paperclip
5
-
6
4
  def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
7
- # ActiveJob currently does not support symbol arguments
8
- self.perform_later(instance_klass, instance_id, attachment_name.to_s)
5
+ queue_name = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
6
+ set(:queue => queue_name).perform_later(instance_klass, instance_id, attachment_name.to_s)
9
7
  end
10
8
 
11
9
  def perform(instance_klass, instance_id, attachment_name)
@@ -13,4 +11,4 @@ module DelayedPaperclip
13
11
  end
14
12
  end
15
13
  end
16
- end
14
+ end
@@ -4,7 +4,8 @@ module DelayedPaperclip
4
4
  module Jobs
5
5
  class DelayedJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
6
6
 
7
- if Gem.loaded_specs['delayed_job'].version >= Gem::Version.new("2.1.0") # this is available in newer versions of DelayedJob. Using the newee Job api thus.
7
+ # This is available in newer versions of DelayedJob. Using the newee Job api thus.
8
+ if Gem.loaded_specs['delayed_job'].version >= Gem::Version.new("2.1.0")
8
9
 
9
10
  def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
10
11
  ::Delayed::Job.enqueue(
@@ -31,4 +32,4 @@ module DelayedPaperclip
31
32
  end
32
33
  end
33
34
  end
34
- end
35
+ end
@@ -3,9 +3,8 @@ require 'resque'
3
3
  module DelayedPaperclip
4
4
  module Jobs
5
5
  class Resque
6
- @queue = :paperclip
7
-
8
6
  def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
7
+ @queue = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
9
8
  ::Resque.enqueue(self, instance_klass, instance_id, attachment_name)
10
9
  end
11
10
 
@@ -14,4 +13,4 @@ module DelayedPaperclip
14
13
  end
15
14
  end
16
15
  end
17
- end
16
+ end
@@ -4,9 +4,15 @@ module DelayedPaperclip
4
4
  module Jobs
5
5
  class Sidekiq
6
6
  include ::Sidekiq::Worker
7
- sidekiq_options :queue => :paperclip
8
7
 
9
8
  def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
9
+ queue_name = instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
10
+ # Sidekiq >= 4.1.0
11
+ if respond_to?(:set)
12
+ set(:queue => queue_name)
13
+ else
14
+ sidekiq_options :queue => queue_name
15
+ end
10
16
  perform_async(instance_klass, instance_id, attachment_name)
11
17
  end
12
18
 
@@ -26,7 +26,7 @@ module DelayedPaperclip
26
26
  def self.insert
27
27
  ActiveRecord::Base.send(:include, DelayedPaperclip::Glue)
28
28
  Paperclip::Attachment.send(:include, DelayedPaperclip::Attachment)
29
- Paperclip::UrlGenerator.send(:include, DelayedPaperclip::UrlGenerator)
29
+ Paperclip::Attachment.default_options[:url_generator] = DelayedPaperclip::UrlGenerator
30
30
  end
31
31
  end
32
32
  end