delayed_paperclip 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.6.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{delayed_paperclip}
8
- s.version = "0.6.3"
8
+ s.version = "0.6.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jesse Storimer"]
@@ -1,15 +1,19 @@
1
1
  class DelayedPaperclipJob < Struct.new(:instance_klass, :instance_id, :attachment_name)
2
2
  def perform
3
- instance = instance_klass.constantize.find(instance_id)
4
-
5
- instance.send("#{attachment_name}_processed!")
6
- begin
3
+ process_job do
7
4
  instance.send(attachment_name).reprocess!
8
- rescue Exception => e
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.send("#{attachment_name}_processed!")
8
- begin
7
+ process_job(instance, attachment_name) do
9
8
  instance.send(attachment_name).reprocess!
10
- rescue Object => e
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
@@ -36,17 +36,12 @@ module Delayed
36
36
  self.save(false)
37
37
  end
38
38
 
39
- define_method "#{name}_processing!" do |*args|
40
- force_save = args.first
39
+ define_method "#{name}_processing!" do
41
40
  return unless column_exists?(:"#{name}_processing")
42
-
43
- unless force_save
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 3
9
- version: 0.6.3
8
+ - 4
9
+ version: 0.6.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jesse Storimer