kt-delayed_paperclip 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a3a7610d65b0a7a7b048ff5597fa8b9836431b4090e4427181c998215cbbbcce
4
+ data.tar.gz: ebc7df68f18f7b892445f0b93a8e07595045da407f2fa9915b80b99cd35ba7f7
5
+ SHA512:
6
+ metadata.gz: 750679eebd3ce3c79d9d010ac183a1299e4ce7baf3593a8b5042f0bf9cfd91c2ca7bffc51bbab893c60f7971c92c46201498d692ed94adfa6f9d7b64e2ac79dc
7
+ data.tar.gz: 6f2f62d878dd92fbddde52d34fad3082d059961ef631fa6b9a9abd8d79078e14c7b9a36ce40471d71176639e83b74cf77723fdde760677166910d8e3a67b1ce7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .DS_Store
2
+ *.log
3
+ pkg/
4
+ public/
5
+ Gemfile.lock
6
+ *.gem
7
+ gemfiles/*.lock
8
+ .ruby-gemset
9
+ .ruby-version
data/.travis.yml ADDED
@@ -0,0 +1,36 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+
5
+ rvm:
6
+ - 2.3.1
7
+ - 2.2.5
8
+ - 2.1.10
9
+ - 2.0
10
+
11
+ gemfile:
12
+ - gemfiles/4.2.gemfile
13
+ - gemfiles/5.0.gemfile
14
+ - gemfiles/5.0_paperclip_master.gemfile
15
+
16
+ # Rails 5.0 requires Ruby >= 2.2.2
17
+ matrix:
18
+ exclude:
19
+ - rvm: 2.1.10
20
+ gemfile: gemfiles/5.0.gemfile
21
+ - rvm: 2.0
22
+ gemfile: gemfiles/5.0.gemfile
23
+ - rvm: 2.1.10
24
+ gemfile: gemfiles/5.0_paperclip_master.gemfile
25
+ - rvm: 2.0
26
+ gemfile: gemfiles/5.0_paperclip_master.gemfile
27
+ # Paperclip >= 5.0 requires Ruby 2.1
28
+ - rvm: 2.0
29
+ gemfile: gemfiles/4.2.gemfile
30
+
31
+ script: "bundle exec rake clean spec"
32
+
33
+ notifications:
34
+ email:
35
+ - james@jamesrgifford.com
36
+ - scott@artsicle.com
data/Appraisals ADDED
@@ -0,0 +1,12 @@
1
+ appraise "4.2" do
2
+ gem "rails", "~> 4.2.0"
3
+ end
4
+
5
+ appraise "5.0" do
6
+ gem "rails", "~> 5.0.0"
7
+ end
8
+
9
+ appraise "5.0-paperclip-master" do
10
+ gem "rails", "~> 5.0.0"
11
+ gem "paperclip", github: "thoughtbot/paperclip"
12
+ end
data/CONTRIBUTING ADDED
@@ -0,0 +1,16 @@
1
+ Contributor Policy
2
+ =================
3
+
4
+ Commit bit. If you have a commit accepted into the project then you get full git access to the repo. If I don't give you this in a timely manner just send me a message.
5
+
6
+ Testing
7
+ ======
8
+
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
+
11
+ Versioning
12
+ =========
13
+
14
+ Don't bump the version in any changes you make or pull in to the project. I'll maintain rights to push the gem to rubygems.org and make releases when appropriate.
15
+
16
+ And please keep the README up to date. Thank you!
data/ChangeLog ADDED
@@ -0,0 +1 @@
1
+ -> https://github.com/jrgifford/delayed_paperclip/releases
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jesse Storimer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
17
+ NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,314 @@
1
+ ======================================================================================
2
+
3
+
4
+ kt-DelayedPaperclip lets you process your [Paperclip](http://github.com/kreeti/kt-paperclip)
5
+ attachments in a background task with [ActiveJob](https://github.com/rails/rails/tree/master/activejob)
6
+
7
+ Why?
8
+ ----
9
+
10
+ The most common use case for Paperclip is to easily attach image files
11
+ to ActiveRecord models. Most of the time these image files will have
12
+ multiple styles and will need to be resized when they are created. This
13
+ is usually a pretty slow operation and should be handled in a background task.
14
+
15
+ I’m sure that everyone knows this, this gem just makes it easy to do.
16
+
17
+ Installation
18
+ ------------
19
+
20
+ Install the gem:
21
+
22
+ ```
23
+ gem install kt-delayed_paperclip
24
+ ```
25
+
26
+ Or even better, add it to your Gemfile.
27
+
28
+ ```
29
+ source "https://rubygems.org"
30
+ gem "kt-delayed_paperclip"
31
+ ```
32
+
33
+ Usage
34
+ -----
35
+
36
+ In your model:
37
+
38
+ ```ruby
39
+ class User < ActiveRecord::Base
40
+ has_attached_file :avatar, styles: {
41
+ medium: "300x300>",
42
+ thumb: "100x100>"
43
+ }
44
+
45
+ process_in_background :avatar
46
+ end
47
+ ```
48
+
49
+ Use your Paperclip attachment just like always in controllers and views.
50
+
51
+ ### Displaying images during processing
52
+
53
+ In the default setup, when you upload an image for the first time and
54
+ try to display it before the job has been completed, Paperclip will be
55
+ none the wiser and output the url of the image which is yet to be
56
+ processed, which will result in a broken image link being displayed on
57
+ the page.
58
+
59
+ To have the missing image url be outputted by paperclip while the image is being processed, all you need to do is add a
60
+ `#{attachment_name}_processing` column to the specific model you want
61
+ to enable this feature for. This feature gracefully degrades and will not affect models which do not have the column added to them.
62
+
63
+ ```ruby
64
+ class AddAvatarProcessingToUser < ActiveRecord::Migration
65
+ def self.up
66
+ add_column :users, :avatar_processing, :boolean
67
+ end
68
+
69
+ def self.down
70
+ remove_column :users, :avatar_processing
71
+ end
72
+ end
73
+
74
+ @user = User.new(avatar: File.new(...))
75
+ @user.save
76
+ @user.avatar.url #=> "/images/original/missing.png"
77
+
78
+ # Process job
79
+
80
+ @user.reload
81
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
82
+ ```
83
+
84
+ #### Custom image for processing
85
+
86
+ This is useful if you have a difference between missing images and
87
+ images currently being processed.
88
+
89
+ ```ruby
90
+ class User < ActiveRecord::Base
91
+ has_attached_file :avatar
92
+
93
+ process_in_background :avatar, processing_image_url: "/images/:style/processing.jpg"
94
+ end
95
+
96
+ @user = User.new(avatar: File.new(...))
97
+ @user.save
98
+ @user.avatar.url #=> "/images/original/processing.png"
99
+
100
+ # Process job
101
+
102
+ @user.reload
103
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
104
+ ```
105
+
106
+ You can also define a custom logic for `processing_image_url`, for
107
+ example to display the original picture while specific formats are being processed.
108
+
109
+ ```ruby
110
+ class Item < ActiveRecord::Base
111
+ has_attached_file :photo
112
+
113
+ process_in_background :photo, processing_image_url: :processing_image_fallback
114
+
115
+ def processing_image_fallback
116
+ options = photo.options
117
+ options[:interpolator].interpolate(options[:url], photo, :original)
118
+ end
119
+ end
120
+ ```
121
+
122
+ Another option is to provide an object which responds to `call` to `processing_image_url` and returns the image url. The method will be called with the attachment as the argument.
123
+
124
+ ```ruby
125
+ class Item < ActiveRecord::Base
126
+ has_attached_file :photo
127
+
128
+ process_in_background :photo, processing_image_url: ->(attachment) {
129
+ ActionController::Base.helpers.image_path("processing.gif")
130
+ }
131
+ end
132
+ ```
133
+
134
+ #### Have processing? status available, but construct image URLs as if delayed_paperclip wasn’t present
135
+
136
+ If you define the `#{attachment_name}_processing` column, but set the
137
+ `url_with_processing` option to false, this opens up other options (other than modifying the url that paperclip returns) for giving feedback to the user while the image is processing. This is useful for advanced situations, for example when dealing with caching systems.
138
+
139
+ Note especially the method #processing? which passes through the value
140
+ of the boolean created via migration.
141
+
142
+ ```ruby
143
+ class User < ActiveRecord::Base
144
+ has_attached_file :avatar
145
+
146
+ process_in_background :avatar, url_with_processing: false
147
+ end
148
+
149
+ @user = User.new(avatar: File.new(...))
150
+ @user.save
151
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
152
+ @user.avatar.processing? #=> true
153
+
154
+ # Process job
155
+
156
+ @user.reload
157
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
158
+ @user.avatar.processing? #=> false
159
+ ```
160
+
161
+ #### Only process certain styles
162
+
163
+ This is useful if you don’t want the background job to reprocess all
164
+ styles.
165
+
166
+ ```ruby
167
+ class User < ActiveRecord::Base
168
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
169
+
170
+ process_in_background :avatar, only_process: [:small]
171
+ end
172
+ ```
173
+
174
+ Like paperclip, you could also supply a lambda function to define
175
+ `only_process` dynamically.
176
+
177
+ ```ruby
178
+ class User < ActiveRecord::Base
179
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
180
+
181
+ process_in_background :avatar, only_process: lambda { |a| a.instance.small_supported? ? [:small, :large] : [:large] }
182
+ end
183
+ ```
184
+
185
+ #### Split processing
186
+
187
+ You can process some styles in the foreground and some in the background
188
+ by setting `only_process` on both `has_attached_file` and
189
+ `process_in_background`.
190
+
191
+ ```ruby
192
+ class User < ActiveRecord::Base
193
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }, only_process: [:small]
194
+
195
+ process_in_background :avatar, only_process: [:medium]
196
+ end
197
+ ```
198
+
199
+ #### Reprocess Without Delay
200
+
201
+ This is useful if you don’t want the background job. It accepts
202
+ individual styles too. Take note, normal `reprocess!` does not accept styles as arguments anymore. It will delegate to DelayedPaperclip and
203
+ reprocess all styles.
204
+
205
+ ```ruby
206
+ class User < ActiveRecord::Base
207
+ has_attached_file :avatar, styles: { small: "25x25#", medium: "50x50#" }
208
+
209
+ process_in_background :avatar
210
+ end
211
+
212
+ @user.avatar.url #=> "/system/images/3/original/IMG_2772.JPG?1267562148"
213
+ @user.avatar.reprocess_without_delay!(:medium)
214
+ ```
215
+
216
+ #### Set queue name
217
+
218
+ You can set queue name for background job. By default it's called "paperclip".
219
+ You can set it by changing global default options or by:
220
+
221
+ ```ruby
222
+ class User < ActiveRecord::Base
223
+ has_attached_file :avatar
224
+
225
+ process_in_background :avatar, queue: "default"
226
+ end
227
+ ```
228
+
229
+ Defaults
230
+ --------
231
+
232
+ Global defaults for all delayed_paperclip instances in your app can be
233
+ defined by changing the DelayedPaperclip.options Hash, this can be useful for setting a default ‘processing image,’ so you won’t have to define it in every `process_in_background` definition.
234
+
235
+ If you’re using Rails you can define a Hash with default options in
236
+ 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:
237
+
238
+ ```ruby
239
+ module YourApp
240
+ class Application < Rails::Application
241
+ # Other code...
242
+
243
+ config.delayed_paperclip_defaults = {
244
+ url_with_processing: true,
245
+ processing_image_url: 'custom_processing.png'
246
+ }
247
+ end
248
+ end
249
+ ```
250
+
251
+ What if I’m not using images?
252
+ -----------------------------
253
+
254
+ This library works no matter what kind of post-processing you are doing
255
+ with Paperclip.
256
+
257
+ Paperclip Post-processors are not working
258
+ -----------------------------------------
259
+
260
+ If you are using custom [post-processing processors](https://github.com/thoughtbot/paperclip#post-processing)
261
+ like this:
262
+
263
+ ```ruby
264
+ # ...
265
+
266
+ has_attached_file :avatar, styles: { thumb: '100x100>' }, processors: [:rotator]
267
+ process_in_background :avatar
268
+
269
+ def rotate!
270
+ # ...
271
+ avatar.reprocess!
272
+ # ...
273
+ end
274
+
275
+ # ...
276
+ ```
277
+
278
+ ...you may encounter an issue where your post-processors are ignored
279
+ ([more info](https://github.com/jrgifford/delayed_paperclip/issues/171)).
280
+ In order to avoid this use `reprocess_without_delay!`
281
+
282
+ ```ruby
283
+ # ...
284
+
285
+ def rotate!
286
+ # ...
287
+ avatar.reprocess_without_delay!
288
+ # ...
289
+ end
290
+
291
+ # ...
292
+ ```
293
+
294
+ Does it work with s3?
295
+ ---------------------
296
+
297
+ Yes.
298
+
299
+ Contributing
300
+ ------------
301
+
302
+ Checkout out [CONTRIBUTING](https://github.com/jrgifford/delayed_paperclip/blob/master/CONTRIBUTING). Run specs with:
303
+
304
+ ```
305
+ # Rspec on all versions
306
+ bundle exec appraisal install
307
+ bundle exec appraisal rake
308
+
309
+ # Rspec on latest stable gems
310
+ bundle exec rake
311
+
312
+ # Rspec on specific rails version
313
+ bundle exec appraisal 5.0 rake
314
+ ```
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rake'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs'
7
+ task default: [:clean, :spec]
8
+
9
+ desc 'Clean up files'
10
+ task :clean do |t|
11
+ FileUtils.rm_rf "doc"
12
+ FileUtils.rm_rf "tmp"
13
+ FileUtils.rm_rf "pkg"
14
+ FileUtils.rm_rf "public"
15
+ Dir.glob("paperclip-*.gem").each { |f| FileUtils.rm f }
16
+ end
17
+
18
+ RSpec::Core::RakeTask.new do |t|
19
+ t.pattern = 'spec/**/*_spec.rb'
20
+ end