delayed_paperclip 0.6.3 → 0.6.4
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.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.4
|
data/delayed_paperclip.gemspec
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
class DelayedPaperclipJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
|
2
2
|
def perform
|
3
|
-
|
4
|
-
|
5
|
-
instance.send("#{attachment_name}_processed!")
|
6
|
-
begin
|
3
|
+
process_job do
|
7
4
|
instance.send(attachment_name).reprocess!
|
8
|
-
|
9
|
-
instance.send("#{attachment_name}_processing!", :save => true)
|
10
|
-
|
11
|
-
# DJ will now pickup this error and do its error handling
|
12
|
-
raise(e)
|
5
|
+
instance.send("#{attachment_name}_processed!")
|
13
6
|
end
|
14
7
|
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def instance
|
11
|
+
@instance ||= instance_klass.constantize.find(instance_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def process_job
|
15
|
+
instance.send(attachment_name).job_is_processing = true
|
16
|
+
yield
|
17
|
+
instance.send(attachment_name).job_is_processing = false
|
18
|
+
end
|
15
19
|
end
|
@@ -4,14 +4,16 @@ class ResquePaperclipJob
|
|
4
4
|
def self.perform(instance_klass, instance_id, attachment_name)
|
5
5
|
instance = instance_klass.constantize.find(instance_id)
|
6
6
|
|
7
|
-
instance
|
8
|
-
begin
|
7
|
+
process_job(instance, attachment_name) do
|
9
8
|
instance.send(attachment_name).reprocess!
|
10
|
-
|
11
|
-
instance.send("#{attachment_name}_processing!", :save => true)
|
12
|
-
|
13
|
-
# Hand the error off to Resque
|
14
|
-
raise(e)
|
9
|
+
instance.send("#{attachment_name}_processed!")
|
15
10
|
end
|
16
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def self.process_job(instance, attachment_name)
|
15
|
+
instance.send(attachment_name).job_is_processing = true
|
16
|
+
yield
|
17
|
+
instance.send(attachment_name).job_is_processing = false
|
18
|
+
end
|
17
19
|
end
|
data/lib/delayed/paperclip.rb
CHANGED
@@ -36,17 +36,12 @@ module Delayed
|
|
36
36
|
self.save(false)
|
37
37
|
end
|
38
38
|
|
39
|
-
define_method "#{name}_processing!" do
|
40
|
-
force_save = args.first
|
39
|
+
define_method "#{name}_processing!" do
|
41
40
|
return unless column_exists?(:"#{name}_processing")
|
42
|
-
|
43
|
-
unless
|
44
|
-
return if self.send(:"#{name}_processing?")
|
45
|
-
return unless self.send(:"#{name}_changed?")
|
46
|
-
end
|
41
|
+
return if self.send(:"#{name}_processing?")
|
42
|
+
return unless self.send(:"#{name}_changed?")
|
47
43
|
|
48
44
|
self.send("#{name}_processing=", true)
|
49
|
-
self.save(false) if force_save
|
50
45
|
end
|
51
46
|
|
52
47
|
self.send("before_#{name}_post_process", :"halt_processing_for_#{name}")
|
@@ -87,7 +82,11 @@ end
|
|
87
82
|
|
88
83
|
module Paperclip
|
89
84
|
class Attachment
|
85
|
+
attr_accessor :job_is_processing
|
86
|
+
|
90
87
|
def url_with_processed style = default_style, include_updated_timestamp = true
|
88
|
+
return url_without_processed style, include_updated_timestamp if job_is_processing
|
89
|
+
|
91
90
|
if !@instance.column_exists?(:"#{@name}_processing")
|
92
91
|
url_without_processed style, include_updated_timestamp
|
93
92
|
else
|
@@ -138,19 +138,4 @@ class DelayedPaperclipTest < Test::Unit::TestCase
|
|
138
138
|
|
139
139
|
assert_match(/images\/.*missing.*/, @dummy.image.url)
|
140
140
|
end
|
141
|
-
|
142
|
-
def test_attachment_processing_with_no_args
|
143
|
-
Dummy.any_instance.expects(:save).never
|
144
|
-
|
145
|
-
@dummy.image_processing!
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_attachment_processing_with_args
|
149
|
-
Dummy.any_instance.stubs(:image_processing?).returns(true)
|
150
|
-
@dummy = reset_dummy(true)
|
151
|
-
@dummy.image_content_type_will_change!
|
152
|
-
@dummy.expects(:save).with(false)
|
153
|
-
|
154
|
-
@dummy.image_processing!(:save => true)
|
155
|
-
end
|
156
141
|
end
|