delayed_paperclip 2.7.1 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3da45f87f8ee8a55f4b3c7c6ba763f6a2680f651
4
- data.tar.gz: 56d4c5b2724facc8e70682b93a3c2196911e673f
3
+ metadata.gz: 9010ad7ec352347ca5ced4c58ad626abdd107884
4
+ data.tar.gz: d1cf800afb079df8745c01b64195dc49cbf8d723
5
5
  SHA512:
6
- metadata.gz: 9408a28957b8007e2503a93927ad61995bf39c61a40d3e384f774e19494b035633d716f2849c3dd9eab281da2d05565cf300ad877005be16623c53c24b82ee7e
7
- data.tar.gz: 5c4ba36bca41329090a6e0ffbc92888c36243768d7a30ced5e5062534e478502bf1cccb40859e7b649e8ad3987c7ed8df1551c9fd5d26a444f5f86016c35122b
6
+ metadata.gz: c766c2943099e7002d32750efff2d7e89563b01cb0d79d564323bc33768ff8e2a052c70b22e777a926d346a3943495a4421cc6ce6f5679eb9e4ab5d526ded1ee
7
+ data.tar.gz: c05abd61fc10c51a0fe5299dfa9b1d0bf5b7b697cbf24e6284923bd18e5a328c9274d71aaeef7548f72e2c0391b44deff848940dcd2ecc7685ccf9a29011b470
data/.gitignore CHANGED
@@ -5,3 +5,5 @@ public/
5
5
  Gemfile.lock
6
6
  *.gem
7
7
  ./gemfiles/rails*.lock
8
+ .ruby-gemset
9
+ .ruby-version
@@ -102,6 +102,35 @@ being processed.
102
102
 
103
103
  </code></pre>
104
104
 
105
+ h4. Have processing? status available, but construct image URLs as if delayed_paperclip wasn't present
106
+
107
+ If you define the #{attachment_name}_processing column, but set the url_with_processing option to false,
108
+ this opens up other options (other than modifying the url that paperclip returns) for giving feedback to
109
+ the user while the image is processing. This is useful for advanced situations, for example when dealing
110
+ with caching systems.
111
+
112
+ Note especially the method .processing? which passes through the value of the boolean created via migration.
113
+
114
+ <pre><code>
115
+
116
+ class User < ActiveRecord::Base
117
+ has_attached_file :avatar
118
+
119
+ process_in_background :avatar, :url_with_processing => false
120
+ end
121
+
122
+ @user = User.new(:avatar => File.new(...))
123
+ @user.save
124
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
125
+ @user.avatar.processing? #=> true
126
+ Delayed::Worker.new.work_off
127
+
128
+ @user.reload
129
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
130
+ @user.avatar.processing? #=> false
131
+
132
+ </code></pre>
133
+
105
134
  h4. Only process certain styles
106
135
 
107
136
  This is useful if you don't want the background job to reprocess all styles.
@@ -114,6 +143,16 @@ This is useful if you don't want the background job to reprocess all styles.
114
143
  end
115
144
  </code></pre>
116
145
 
146
+ Like paperclip, you could also supply a lambda function to define only_process dynamically.
147
+
148
+ <pre><code>
149
+ class User < ActiveRecord::Base
150
+ has_attached_file :avatar, :styles => { :small => "25x25#", :medium => "50x50x" }
151
+
152
+ process_in_background :avatar, :only_process => lambda { |a| a.instance.small_supported? ? [:small, :large] : [:large] }
153
+ end
154
+ </code></pre>
155
+
117
156
  h4. Split processing
118
157
 
119
158
  You can process some styles in the foreground and some in the background by setting only_process on both has_attached_file and process_in_background.
@@ -142,6 +181,28 @@ styles as arguments anymore. It will delegate to DelayedPaperclip and reprocess
142
181
  @user.avatar.reprocess_without_delay!(:medium)
143
182
  </code></pre>
144
183
 
184
+ h2. Defaults
185
+
186
+ Global defaults for all delayed_paperclip instances in your app can be defined by changing the
187
+ DelayedPaperclip.options Hash, this can be useful for setting a default 'processing image,' so you
188
+ won't have to define it in every process_in_background definition.
189
+
190
+ If you're using Rails you can define a Hash with default options in config/application.rb or in any
191
+ of the config/environments/*.rb files on config.delayed_paperclip_defaults, these will get merged into
192
+ DelayedPaperclip.options as your Rails app boots. An example:
193
+
194
+ <pre><code>
195
+ module YourApp
196
+ class Application < Rails::Application
197
+ # Other code...
198
+
199
+ config.delayed_paperclip_defaults = {
200
+ :url_with_processing => true,
201
+ :processing_image_url => 'custom_processing.png'
202
+ }
203
+ end
204
+ end
205
+ </code></pre>
145
206
 
146
207
  h2. What if I'm not using images?
147
208
 
@@ -153,4 +214,6 @@ Yes.
153
214
 
154
215
  h2. Contributing
155
216
 
156
- Checkout out CONTRIBUTING for more info.
217
+ Checkout out CONTRIBUTING. In short, you'll need a redis server running for testing. Run all tests with
218
+
219
+ <pre><code>rake</code></pre>
@@ -19,7 +19,7 @@ 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'
23
23
  s.add_development_dependency 'appraisal'
24
24
  s.add_development_dependency 'rake'
25
25
  s.add_development_dependency 'bundler'
@@ -159,5 +159,5 @@ DEPENDENCIES
159
159
  rake
160
160
  resque
161
161
  rspec
162
- sidekiq (< 3.0)
162
+ sidekiq
163
163
  sqlite3
@@ -157,5 +157,5 @@ DEPENDENCIES
157
157
  rake
158
158
  resque
159
159
  rspec
160
- sidekiq (< 3.0)
160
+ sidekiq
161
161
  sqlite3
@@ -153,5 +153,5 @@ DEPENDENCIES
153
153
  rake
154
154
  resque
155
155
  rspec
156
- sidekiq (< 3.0)
156
+ sidekiq
157
157
  sqlite3
@@ -57,7 +57,7 @@ module DelayedPaperclip
57
57
  :priority => 0,
58
58
  :only_process => only_process_default,
59
59
  :url_with_processing => DelayedPaperclip.options[:url_with_processing],
60
- :processing_image_url => options[:processing_image_url],
60
+ :processing_image_url => DelayedPaperclip.options[:processing_image_url],
61
61
  :queue => nil
62
62
  }.each do |option, default|
63
63
 
@@ -51,10 +51,16 @@ module DelayedPaperclip
51
51
  !split_processing? || delayed_options[:only_process].include?(style)
52
52
  end
53
53
 
54
+ def delayed_only_process
55
+ only_process = delayed_options[:only_process].dup
56
+ only_process = only_process.call(self) if only_process.respond_to?(:call)
57
+ only_process.map(&:to_sym)
58
+ end
59
+
54
60
  def process_delayed!
55
61
  self.job_is_processing = true
56
62
  self.post_processing = true
57
- reprocess!(*delayed_options[:only_process])
63
+ reprocess!(*delayed_only_process)
58
64
  self.job_is_processing = false
59
65
  update_processing_column
60
66
  end
@@ -7,10 +7,14 @@ module DelayedPaperclip
7
7
 
8
8
  # On initialzation, include DelayedPaperclip
9
9
  class Railtie < Rails::Railtie
10
- initializer 'delayed_paperclip.insert_into_active_record' do
10
+ initializer 'delayed_paperclip.insert_into_active_record' do |app|
11
11
  ActiveSupport.on_load :active_record do
12
12
  DelayedPaperclip::Railtie.insert
13
13
  end
14
+
15
+ if app.config.respond_to?(:delayed_paperclip_defaults)
16
+ DelayedPaperclip.options.merge!(app.config.delayed_paperclip_defaults)
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -1,3 +1,3 @@
1
1
  module DelayedPaperclip
2
- VERSION = "2.7.1"
2
+ VERSION = "2.8.0"
3
3
  end
@@ -107,6 +107,34 @@ describe DelayedPaperclip::Attachment do
107
107
  end
108
108
  end
109
109
 
110
+ describe "delayed_only_process" do
111
+ context "without only_process options" do
112
+ it "returns []" do
113
+ expect(dummy.image.delayed_only_process).to eq []
114
+ end
115
+ end
116
+
117
+ context "with only_process options" do
118
+ before :each do
119
+ reset_dummy(paperclip: { only_process: [:small, :large] } )
120
+ end
121
+
122
+ it "returns [:small, :large]" do
123
+ expect(dummy.image.delayed_only_process).to eq [:small, :large]
124
+ end
125
+ end
126
+
127
+ context "with only_process set with callable" do
128
+ before :each do
129
+ reset_dummy(paperclip: { only_process: lambda { |a| [:small, :large] } } )
130
+ end
131
+
132
+ it "returns [:small, :large]" do
133
+ expect(dummy.image.delayed_only_process).to eq [:small, :large]
134
+ end
135
+ end
136
+ end
137
+
110
138
  describe "process_delayed!" do
111
139
  it "sets job_is_processing to true" do
112
140
  dummy.image.expects(:job_is_processing=).with(true).once
@@ -136,6 +164,17 @@ describe DelayedPaperclip::Attachment do
136
164
  dummy.image.process_delayed!
137
165
  end
138
166
  end
167
+
168
+ context "with only_process set with callable" do
169
+ before :each do
170
+ reset_dummy(paperclip: { only_process: lambda { |a| [:small, :large] } } )
171
+ end
172
+
173
+ it "calls reprocess! with options" do
174
+ dummy.image.expects(:reprocess!).with(:small, :large)
175
+ dummy.image.process_delayed!
176
+ end
177
+ end
139
178
  end
140
179
 
141
180
  describe "#processing_image_url" do
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require 'sidekiq'
2
+ require 'sidekiq/api'
3
3
 
4
4
  describe "Sidekiq" do
5
5
 
@@ -45,4 +45,4 @@ describe "Sidekiq" do
45
45
  Sidekiq::Queue.new(:paperclip).size
46
46
  end
47
47
 
48
- end
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -11,174 +11,174 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-03-28 00:00:00.000000000 Z
14
+ date: 2014-06-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: paperclip
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: '3.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.3'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mocha
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - '>='
34
+ - - ">="
35
35
  - !ruby/object:Gem::Version
36
36
  version: '0'
37
37
  type: :development
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - '>='
41
+ - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: rspec
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sqlite3
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - '>='
69
+ - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: delayed_job
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - '>='
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - '>='
83
+ - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  - !ruby/object:Gem::Dependency
87
87
  name: delayed_job_active_record
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: resque
102
102
  requirement: !ruby/object:Gem::Requirement
103
103
  requirements:
104
- - - '>='
104
+ - - ">="
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  type: :development
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - '>='
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: sidekiq
116
116
  requirement: !ruby/object:Gem::Requirement
117
117
  requirements:
118
- - - <
118
+ - - ">="
119
119
  - !ruby/object:Gem::Version
120
- version: '3.0'
120
+ version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
123
  version_requirements: !ruby/object:Gem::Requirement
124
124
  requirements:
125
- - - <
125
+ - - ">="
126
126
  - !ruby/object:Gem::Version
127
- version: '3.0'
127
+ version: '0'
128
128
  - !ruby/object:Gem::Dependency
129
129
  name: appraisal
130
130
  requirement: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - '>='
132
+ - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  type: :development
136
136
  prerelease: false
137
137
  version_requirements: !ruby/object:Gem::Requirement
138
138
  requirements:
139
- - - '>='
139
+ - - ">="
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  - !ruby/object:Gem::Dependency
143
143
  name: rake
144
144
  requirement: !ruby/object:Gem::Requirement
145
145
  requirements:
146
- - - '>='
146
+ - - ">="
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  type: :development
150
150
  prerelease: false
151
151
  version_requirements: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - '>='
153
+ - - ">="
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  - !ruby/object:Gem::Dependency
157
157
  name: bundler
158
158
  requirement: !ruby/object:Gem::Requirement
159
159
  requirements:
160
- - - '>='
160
+ - - ">="
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  type: :development
164
164
  prerelease: false
165
165
  version_requirements: !ruby/object:Gem::Requirement
166
166
  requirements:
167
- - - '>='
167
+ - - ">="
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  - !ruby/object:Gem::Dependency
171
171
  name: railties
172
172
  requirement: !ruby/object:Gem::Requirement
173
173
  requirements:
174
- - - '>='
174
+ - - ">="
175
175
  - !ruby/object:Gem::Version
176
176
  version: '0'
177
177
  type: :development
178
178
  prerelease: false
179
179
  version_requirements: !ruby/object:Gem::Requirement
180
180
  requirements:
181
- - - '>='
181
+ - - ">="
182
182
  - !ruby/object:Gem::Version
183
183
  version: '0'
184
184
  description: Process your Paperclip attachments in the background with DelayedJob,
@@ -190,11 +190,9 @@ executables: []
190
190
  extensions: []
191
191
  extra_rdoc_files: []
192
192
  files:
193
- - .gitignore
194
- - .rbenv-version
195
- - .ruby-gemset
196
- - .ruby-version
197
- - .travis.yml
193
+ - ".gitignore"
194
+ - ".rbenv-version"
195
+ - ".travis.yml"
198
196
  - Appraisals
199
197
  - CONTRIBUTING
200
198
  - ChangeLog
@@ -249,12 +247,12 @@ require_paths:
249
247
  - lib
250
248
  required_ruby_version: !ruby/object:Gem::Requirement
251
249
  requirements:
252
- - - '>='
250
+ - - ">="
253
251
  - !ruby/object:Gem::Version
254
252
  version: '0'
255
253
  required_rubygems_version: !ruby/object:Gem::Requirement
256
254
  requirements:
257
- - - '>='
255
+ - - ">="
258
256
  - !ruby/object:Gem::Version
259
257
  version: '0'
260
258
  requirements: []
@@ -1 +0,0 @@
1
- delayed_paperclip
@@ -1 +0,0 @@
1
- 2.0.0-p195