Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Added split processing option #62

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ This is useful if you don't want the background job to reprocess all styles.
end
</code></pre>

h4. Split processing

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.

<pre><code>
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :small => "25x25#", :medium => "50x50x" }, :only_process => [:small]

process_in_background :avatar, :only_process => [:medium]
end
</code></pre>

h4. Reprocess Without Delay

This is useful if you don't want the background job. It accepts individual styles to. Take note, normal `reprocess!` does not accept
Expand Down
8 changes: 6 additions & 2 deletions lib/delayed_paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def self.included(base)
module InstanceMethods

def delayed_options
@instance.class.paperclip_definitions[@name][:delayed]
@options[:delayed]
end

# Attr accessor in Paperclip
def post_processing_with_delay
!delay_processing?
!delay_processing? || split_processing?
end

def post_processing_with_delay=(value)
Expand All @@ -34,6 +34,10 @@ def delay_processing?
!@post_processing_with_delay
end
end

def split_processing?
@options[:only_process] && @options[:only_process] != @options[:delayed][:only_process]
end

def processing?
@instance.send(:"#{@name}_processing?")
Expand Down
9 changes: 9 additions & 0 deletions test/base_delayed_paperclip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ def test_delayed_paperclip_functioning_with_paperclip_only_process_option
dummy.save!
process_jobs
end

def test_delayed_paperclip_functioning_with_only_process_and_paperclip_only_process_option
reset_class "Dummy", :with_processed => true, :only_process => [:small], :paperclip => { :only_process => [:thumbnail] }
Paperclip::Attachment.any_instance.expects(:post_process).with(:thumbnail)
Paperclip::Attachment.any_instance.expects(:reprocess!).with(:small)
dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
dummy.save!
process_jobs
end

def test_delayed_paperclip_should_convert_image_formats
reset_class "Dummy", :with_processed => true, :paperclip => { :styles => {:thumbnail => ['12x12', :jpg]} }
Expand Down