delayed_paperclip 2.6.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -9
- data/Appraisals +4 -8
- data/Gemfile +1 -9
- data/README.textile +19 -3
- data/Rakefile +1 -1
- data/delayed_paperclip.gemspec +8 -3
- data/gemfiles/rails3_1.gemfile +1 -4
- data/gemfiles/rails3_1.gemfile.lock +70 -68
- data/gemfiles/rails3_2.gemfile +1 -4
- data/gemfiles/rails3_2.gemfile.lock +72 -70
- data/gemfiles/rails4.gemfile +7 -0
- data/gemfiles/rails4.gemfile.lock +157 -0
- data/lib/delayed_paperclip.rb +6 -3
- data/lib/delayed_paperclip/attachment.rb +17 -4
- data/lib/delayed_paperclip/jobs/delayed_job.rb +5 -3
- data/lib/delayed_paperclip/url_generator.rb +22 -4
- data/lib/delayed_paperclip/version.rb +1 -1
- data/spec/delayed_paperclip/attachment_spec.rb +67 -6
- data/spec/delayed_paperclip/class_methods_spec.rb +8 -5
- data/spec/delayed_paperclip/url_generator_spec.rb +36 -5
- data/spec/delayed_paperclip_spec.rb +6 -3
- data/spec/spec_helper.rb +16 -5
- data/test/base_delayed_paperclip_test.rb +14 -0
- data/test/test_helper.rb +13 -2
- metadata +82 -12
- data/gemfiles/paperclip3_5.gemfile +0 -11
- data/gemfiles/paperclip3_5.gemfile.lock +0 -160
- data/gemfiles/rails3.gemfile +0 -10
- data/gemfiles/rails3.gemfile.lock +0 -151
@@ -0,0 +1,157 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
delayed_paperclip (2.7.0)
|
5
|
+
paperclip (>= 3.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (4.0.3)
|
11
|
+
actionpack (= 4.0.3)
|
12
|
+
mail (~> 2.5.4)
|
13
|
+
actionpack (4.0.3)
|
14
|
+
activesupport (= 4.0.3)
|
15
|
+
builder (~> 3.1.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
rack (~> 1.5.2)
|
18
|
+
rack-test (~> 0.6.2)
|
19
|
+
activemodel (4.0.3)
|
20
|
+
activesupport (= 4.0.3)
|
21
|
+
builder (~> 3.1.0)
|
22
|
+
activerecord (4.0.3)
|
23
|
+
activemodel (= 4.0.3)
|
24
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
25
|
+
activesupport (= 4.0.3)
|
26
|
+
arel (~> 4.0.0)
|
27
|
+
activerecord-deprecated_finders (1.0.3)
|
28
|
+
activesupport (4.0.3)
|
29
|
+
i18n (~> 0.6, >= 0.6.4)
|
30
|
+
minitest (~> 4.2)
|
31
|
+
multi_json (~> 1.3)
|
32
|
+
thread_safe (~> 0.1)
|
33
|
+
tzinfo (~> 0.3.37)
|
34
|
+
appraisal (0.5.2)
|
35
|
+
bundler
|
36
|
+
rake
|
37
|
+
arel (4.0.2)
|
38
|
+
atomic (1.1.14)
|
39
|
+
builder (3.1.4)
|
40
|
+
celluloid (0.15.2)
|
41
|
+
timers (~> 1.1.0)
|
42
|
+
climate_control (0.0.3)
|
43
|
+
activesupport (>= 3.0)
|
44
|
+
cocaine (0.5.3)
|
45
|
+
climate_control (>= 0.0.3, < 1.0)
|
46
|
+
connection_pool (1.2.0)
|
47
|
+
delayed_job (4.0.0)
|
48
|
+
activesupport (>= 3.0, < 4.1)
|
49
|
+
delayed_job_active_record (4.0.0)
|
50
|
+
activerecord (>= 3.0, < 4.1)
|
51
|
+
delayed_job (>= 3.0, < 4.1)
|
52
|
+
diff-lcs (1.2.5)
|
53
|
+
erubis (2.7.0)
|
54
|
+
hike (1.2.3)
|
55
|
+
i18n (0.6.9)
|
56
|
+
json (1.8.1)
|
57
|
+
mail (2.5.4)
|
58
|
+
mime-types (~> 1.16)
|
59
|
+
treetop (~> 1.4.8)
|
60
|
+
metaclass (0.0.3)
|
61
|
+
mime-types (1.25.1)
|
62
|
+
minitest (4.7.5)
|
63
|
+
mocha (1.0.0)
|
64
|
+
metaclass (~> 0.0.1)
|
65
|
+
mono_logger (1.1.0)
|
66
|
+
multi_json (1.8.4)
|
67
|
+
paperclip (4.1.0)
|
68
|
+
activemodel (>= 3.0.0)
|
69
|
+
activesupport (>= 3.0.0)
|
70
|
+
cocaine (~> 0.5.3)
|
71
|
+
mime-types
|
72
|
+
polyglot (0.3.4)
|
73
|
+
rack (1.5.2)
|
74
|
+
rack-protection (1.5.2)
|
75
|
+
rack
|
76
|
+
rack-test (0.6.2)
|
77
|
+
rack (>= 1.0)
|
78
|
+
rails (4.0.3)
|
79
|
+
actionmailer (= 4.0.3)
|
80
|
+
actionpack (= 4.0.3)
|
81
|
+
activerecord (= 4.0.3)
|
82
|
+
activesupport (= 4.0.3)
|
83
|
+
bundler (>= 1.3.0, < 2.0)
|
84
|
+
railties (= 4.0.3)
|
85
|
+
sprockets-rails (~> 2.0.0)
|
86
|
+
railties (4.0.3)
|
87
|
+
actionpack (= 4.0.3)
|
88
|
+
activesupport (= 4.0.3)
|
89
|
+
rake (>= 0.8.7)
|
90
|
+
thor (>= 0.18.1, < 2.0)
|
91
|
+
rake (10.1.1)
|
92
|
+
redis (3.0.7)
|
93
|
+
redis-namespace (1.4.1)
|
94
|
+
redis (~> 3.0.4)
|
95
|
+
resque (1.25.1)
|
96
|
+
mono_logger (~> 1.0)
|
97
|
+
multi_json (~> 1.0)
|
98
|
+
redis-namespace (~> 1.2)
|
99
|
+
sinatra (>= 0.9.2)
|
100
|
+
vegas (~> 0.1.2)
|
101
|
+
rspec (2.14.1)
|
102
|
+
rspec-core (~> 2.14.0)
|
103
|
+
rspec-expectations (~> 2.14.0)
|
104
|
+
rspec-mocks (~> 2.14.0)
|
105
|
+
rspec-core (2.14.7)
|
106
|
+
rspec-expectations (2.14.5)
|
107
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
108
|
+
rspec-mocks (2.14.5)
|
109
|
+
sidekiq (2.17.6)
|
110
|
+
celluloid (>= 0.15.2)
|
111
|
+
connection_pool (>= 1.0.0)
|
112
|
+
json
|
113
|
+
redis (>= 3.0.6)
|
114
|
+
redis-namespace (>= 1.3.1)
|
115
|
+
sinatra (1.4.4)
|
116
|
+
rack (~> 1.4)
|
117
|
+
rack-protection (~> 1.4)
|
118
|
+
tilt (~> 1.3, >= 1.3.4)
|
119
|
+
sprockets (2.10.1)
|
120
|
+
hike (~> 1.2)
|
121
|
+
multi_json (~> 1.0)
|
122
|
+
rack (~> 1.0)
|
123
|
+
tilt (~> 1.1, != 1.3.0)
|
124
|
+
sprockets-rails (2.0.1)
|
125
|
+
actionpack (>= 3.0)
|
126
|
+
activesupport (>= 3.0)
|
127
|
+
sprockets (~> 2.8)
|
128
|
+
sqlite3 (1.3.8)
|
129
|
+
thor (0.18.1)
|
130
|
+
thread_safe (0.1.3)
|
131
|
+
atomic
|
132
|
+
tilt (1.4.1)
|
133
|
+
timers (1.1.0)
|
134
|
+
treetop (1.4.15)
|
135
|
+
polyglot
|
136
|
+
polyglot (>= 0.3.1)
|
137
|
+
tzinfo (0.3.38)
|
138
|
+
vegas (0.1.11)
|
139
|
+
rack (>= 1.0.0)
|
140
|
+
|
141
|
+
PLATFORMS
|
142
|
+
ruby
|
143
|
+
|
144
|
+
DEPENDENCIES
|
145
|
+
appraisal
|
146
|
+
bundler
|
147
|
+
delayed_job
|
148
|
+
delayed_job_active_record
|
149
|
+
delayed_paperclip!
|
150
|
+
mocha
|
151
|
+
rails (~> 4.0.3)
|
152
|
+
railties
|
153
|
+
rake
|
154
|
+
resque
|
155
|
+
rspec
|
156
|
+
sidekiq
|
157
|
+
sqlite3
|
data/lib/delayed_paperclip.rb
CHANGED
@@ -30,7 +30,7 @@ module DelayedPaperclip
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def process_job(instance_klass, instance_id, attachment_name)
|
33
|
-
instance_klass.constantize.find(instance_id).
|
33
|
+
instance_klass.constantize.unscoped.find(instance_id).
|
34
34
|
send(attachment_name).
|
35
35
|
process_delayed!
|
36
36
|
end
|
@@ -51,11 +51,14 @@ module DelayedPaperclip
|
|
51
51
|
paperclip_definitions[name][:delayed] = {}
|
52
52
|
|
53
53
|
# Set Defaults
|
54
|
+
only_process_default = paperclip_definitions[name][:only_process]
|
55
|
+
only_process_default ||= []
|
54
56
|
{
|
55
57
|
:priority => 0,
|
56
|
-
:only_process =>
|
58
|
+
:only_process => only_process_default,
|
57
59
|
:url_with_processing => DelayedPaperclip.options[:url_with_processing],
|
58
|
-
:processing_image_url => options[:processing_image_url]
|
60
|
+
:processing_image_url => options[:processing_image_url],
|
61
|
+
:queue => nil
|
59
62
|
}.each do |option, default|
|
60
63
|
|
61
64
|
paperclip_definitions[name][:delayed][option] = options.key?(option) ? options[option] : default
|
@@ -13,12 +13,12 @@ module DelayedPaperclip
|
|
13
13
|
module InstanceMethods
|
14
14
|
|
15
15
|
def delayed_options
|
16
|
-
@
|
16
|
+
@options[:delayed]
|
17
17
|
end
|
18
18
|
|
19
19
|
# Attr accessor in Paperclip
|
20
20
|
def post_processing_with_delay
|
21
|
-
!delay_processing?
|
21
|
+
!delay_processing? || split_processing?
|
22
22
|
end
|
23
23
|
|
24
24
|
def post_processing_with_delay=(value)
|
@@ -35,8 +35,21 @@ module DelayedPaperclip
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def split_processing?
|
39
|
+
options[:only_process] &&
|
40
|
+
options[:only_process] !=
|
41
|
+
options[:delayed][:only_process]
|
42
|
+
end
|
43
|
+
|
38
44
|
def processing?
|
39
|
-
|
45
|
+
column_name = :"#{@name}_processing?"
|
46
|
+
@instance.respond_to?(column_name) && @instance.send(column_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def processing_style?(style)
|
50
|
+
return false if !processing?
|
51
|
+
|
52
|
+
!split_processing? || delayed_options[:only_process].include?(style)
|
40
53
|
end
|
41
54
|
|
42
55
|
def process_delayed!
|
@@ -47,7 +60,7 @@ module DelayedPaperclip
|
|
47
60
|
end
|
48
61
|
|
49
62
|
def processing_image_url
|
50
|
-
processing_image_url =
|
63
|
+
processing_image_url = delayed_options[:processing_image_url]
|
51
64
|
processing_image_url = processing_image_url.call(self) if processing_image_url.respond_to?(:call)
|
52
65
|
processing_image_url
|
53
66
|
end
|
@@ -4,12 +4,13 @@ module DelayedPaperclip
|
|
4
4
|
module Jobs
|
5
5
|
class DelayedJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
|
6
6
|
|
7
|
-
if
|
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.
|
8
8
|
|
9
9
|
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
10
10
|
::Delayed::Job.enqueue(
|
11
11
|
:payload_object => new(instance_klass, instance_id, attachment_name),
|
12
|
-
:priority => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i
|
12
|
+
:priority => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i,
|
13
|
+
:queue => instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
13
14
|
)
|
14
15
|
end
|
15
16
|
|
@@ -18,7 +19,8 @@ module DelayedPaperclip
|
|
18
19
|
def self.enqueue_delayed_paperclip(instance_klass, instance_id, attachment_name)
|
19
20
|
::Delayed::Job.enqueue(
|
20
21
|
new(instance_klass, instance_id, attachment_name),
|
21
|
-
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i
|
22
|
+
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:priority].to_i,
|
23
|
+
instance_klass.constantize.paperclip_definitions[attachment_name][:delayed][:queue]
|
22
24
|
)
|
23
25
|
end
|
24
26
|
|
@@ -5,10 +5,21 @@ module DelayedPaperclip
|
|
5
5
|
def self.included(base)
|
6
6
|
base.alias_method_chain :most_appropriate_url, :processed
|
7
7
|
base.alias_method_chain :timestamp_possible?, :processed
|
8
|
+
base.alias_method_chain :for, :processed
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def for_with_processed(style_name, options)
|
12
|
+
most_appropriate_url = most_appropriate_url(style_name)
|
13
|
+
|
14
|
+
escape_url_as_needed(
|
15
|
+
timestamp_as_needed(
|
16
|
+
@attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name),
|
17
|
+
options
|
18
|
+
), options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def most_appropriate_url_with_processed(style = nil)
|
22
|
+
if @attachment.original_filename.nil? || delayed_default_url?(style)
|
12
23
|
if @attachment.delayed_options.nil? || @attachment.processing_image_url.nil? || !@attachment.processing?
|
13
24
|
default_url
|
14
25
|
else
|
@@ -27,11 +38,11 @@ module DelayedPaperclip
|
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
30
|
-
def delayed_default_url?
|
41
|
+
def delayed_default_url?(style = nil)
|
31
42
|
return false if @attachment.job_is_processing
|
32
43
|
return false if @attachment.dirty?
|
33
44
|
return false if not @attachment.delayed_options.try(:[], :url_with_processing)
|
34
|
-
return false if not
|
45
|
+
return false if not processing?(style)
|
35
46
|
true
|
36
47
|
|
37
48
|
# OLD CRAZY CONDITIONAL
|
@@ -43,6 +54,13 @@ module DelayedPaperclip
|
|
43
54
|
# !(@attachment.instance.respond_to?(:"#{@attachment.name}_processing?") && @attachment.processing?)
|
44
55
|
# )
|
45
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def processing?(style)
|
60
|
+
return true if @attachment.processing?
|
61
|
+
|
62
|
+
return @attachment.processing_style?(style) if style
|
63
|
+
end
|
46
64
|
end
|
47
65
|
|
48
66
|
end
|
@@ -2,11 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe DelayedPaperclip::Attachment do
|
4
4
|
|
5
|
-
before :
|
5
|
+
before :each do
|
6
6
|
DelayedPaperclip.options[:background_job_class] = DelayedPaperclip::Jobs::Resque
|
7
|
-
reset_dummy
|
7
|
+
reset_dummy(dummy_options)
|
8
8
|
end
|
9
9
|
|
10
|
+
let(:dummy_options) { {} }
|
10
11
|
let(:dummy) { Dummy.create }
|
11
12
|
|
12
13
|
describe "#delayed_options" do
|
@@ -14,12 +15,12 @@ describe DelayedPaperclip::Attachment do
|
|
14
15
|
it "returns the specific options for delayed paperclip" do
|
15
16
|
dummy.image.delayed_options.should == {
|
16
17
|
:priority => 0,
|
17
|
-
:only_process =>
|
18
|
+
:only_process => [],
|
18
19
|
:url_with_processing => true,
|
19
|
-
:processing_image_url => nil
|
20
|
+
:processing_image_url => nil,
|
21
|
+
:queue => nil
|
20
22
|
}
|
21
23
|
end
|
22
|
-
|
23
24
|
end
|
24
25
|
|
25
26
|
describe "#post_processing_with_delay" do
|
@@ -51,6 +52,59 @@ describe DelayedPaperclip::Attachment do
|
|
51
52
|
dummy.expects(:image_processing?)
|
52
53
|
dummy.image.processing?
|
53
54
|
end
|
55
|
+
|
56
|
+
context "without a processing column" do
|
57
|
+
let(:dummy_options) { { with_processed: false } }
|
58
|
+
|
59
|
+
it "returns false" do
|
60
|
+
expect(dummy.image.processing?).to be_false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "processing_stye?" do
|
66
|
+
let(:style) { :background }
|
67
|
+
let(:processing_style?) { dummy.image.processing_style?(style) }
|
68
|
+
|
69
|
+
context "without a processing column" do
|
70
|
+
let(:dummy_options) { { with_processed: true, process_column: false } }
|
71
|
+
|
72
|
+
specify { expect(processing_style?).to be_false }
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with a processing column" do
|
76
|
+
context "when not processing" do
|
77
|
+
before { dummy.image_processing = false }
|
78
|
+
|
79
|
+
specify { expect(processing_style?).to be_false }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when processing" do
|
83
|
+
before { dummy.image_processing = true }
|
84
|
+
|
85
|
+
context "when not split processing" do
|
86
|
+
specify { expect(processing_style?).to be_true }
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when split processing" do
|
90
|
+
let(:dummy_options) { {
|
91
|
+
paperclip: {
|
92
|
+
styles: {
|
93
|
+
online: "400x400x",
|
94
|
+
background: "600x600x"
|
95
|
+
},
|
96
|
+
only_process: [:online]
|
97
|
+
},
|
98
|
+
|
99
|
+
delayed_paperclip: {
|
100
|
+
only_process: [:background]
|
101
|
+
}
|
102
|
+
}}
|
103
|
+
|
104
|
+
specify { expect(processing_style?).to be }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
54
108
|
end
|
55
109
|
|
56
110
|
describe "process_delayed!" do
|
@@ -120,6 +174,13 @@ describe DelayedPaperclip::Attachment do
|
|
120
174
|
|
121
175
|
dummy.image_processing.should be_false
|
122
176
|
end
|
177
|
+
|
178
|
+
it "still flushes temp files" do
|
179
|
+
dummy.image = File.open("#{ROOT}/spec/fixtures/12k.png")
|
180
|
+
paths = dummy.image.queued_for_write.values.map(&:path)
|
181
|
+
dummy.image.after_flush_writes_with_processing
|
182
|
+
paths.none?{ |path| File.exists?(path) }.should be_true
|
183
|
+
end
|
123
184
|
end
|
124
185
|
|
125
186
|
describe "#save_with_prepare_enqueueing" do
|
@@ -150,4 +211,4 @@ describe DelayedPaperclip::Attachment do
|
|
150
211
|
dummy.image.instance_variable_get(:@post_processing_with_delay).should == true
|
151
212
|
end
|
152
213
|
end
|
153
|
-
end
|
214
|
+
end
|
@@ -18,9 +18,10 @@ describe DelayedPaperclip::ClassMethods do
|
|
18
18
|
Dummy.paperclip_definitions.should == { :image => {
|
19
19
|
:delayed => {
|
20
20
|
:priority => 0,
|
21
|
-
:only_process =>
|
21
|
+
:only_process => [],
|
22
22
|
:url_with_processing => true,
|
23
|
-
:processing_image_url => nil
|
23
|
+
:processing_image_url => nil,
|
24
|
+
:queue => nil}
|
24
25
|
}
|
25
26
|
}
|
26
27
|
end
|
@@ -34,9 +35,10 @@ describe DelayedPaperclip::ClassMethods do
|
|
34
35
|
Dummy.paperclip_definitions.should == { :image => {
|
35
36
|
:delayed => {
|
36
37
|
:priority => 0,
|
37
|
-
:only_process =>
|
38
|
+
:only_process => [],
|
38
39
|
:url_with_processing => true,
|
39
|
-
:processing_image_url => "/processing/url"
|
40
|
+
:processing_image_url => "/processing/url",
|
41
|
+
:queue => nil}
|
40
42
|
}
|
41
43
|
}
|
42
44
|
end
|
@@ -55,7 +57,8 @@ describe DelayedPaperclip::ClassMethods do
|
|
55
57
|
:priority => 0,
|
56
58
|
:only_process => [:small, :large],
|
57
59
|
:url_with_processing => true,
|
58
|
-
:processing_image_url => nil
|
60
|
+
:processing_image_url => nil,
|
61
|
+
:queue => nil}
|
59
62
|
}
|
60
63
|
}
|
61
64
|
end
|