Commit 2fda5b10 by Michał Szajbe Committed by Jon Yurek

Now Attachment instance is passed as third argument to Processor#make.

(cherry picked from commit e655fbe502fbae2b538922b35c6d2f55b1fee3d1)
parent 35b912ac
...@@ -359,7 +359,7 @@ module Paperclip ...@@ -359,7 +359,7 @@ module Paperclip
raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank? raise RuntimeError.new("Style #{name} has no processors defined.") if args[:processors].blank?
@queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor| @queued_for_write[name] = args[:processors].inject(@queued_for_write[:original]) do |file, processor|
log("Processing #{name} #{file} in the #{processor} processor.") log("Processing #{name} #{file} in the #{processor} processor.")
Paperclip.processor(processor).make(file, args) Paperclip.processor(processor).make(file, args, self)
end end
rescue PaperclipError => e rescue PaperclipError => e
log("An error was received while processing: #{e.inspect}") log("An error was received while processing: #{e.inspect}")
......
...@@ -17,18 +17,19 @@ module Paperclip ...@@ -17,18 +17,19 @@ module Paperclip
# See Paperclip.run for more information about using command-line # See Paperclip.run for more information about using command-line
# utilities from within Processors. # utilities from within Processors.
class Processor class Processor
attr_accessor :file, :options attr_accessor :file, :options, :attachment
def initialize file, options = {} def initialize file, options = {}, attachment = nil
@file = file @file = file
@options = options @options = options
@attachment = attachment
end end
def make def make
end end
def self.make file, options = {} def self.make file, options = {}, attachment = nil
new(file, options).make new(file, options, attachment).make
end end
end end
......
...@@ -10,7 +10,7 @@ module Paperclip ...@@ -10,7 +10,7 @@ module Paperclip
# unless specified. Thumbnail creation will raise no errors unless # unless specified. Thumbnail creation will raise no errors unless
# +whiny+ is true (which it is, by default. If +convert_options+ is # +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion # set, the options will be appended to the convert command upon image conversion
def initialize file, options = {} def initialize file, options = {}, attachment = nil
super super
geometry = options[:geometry] geometry = options[:geometry]
@file = file @file = file
......
...@@ -317,8 +317,13 @@ class AttachmentTest < Test::Unit::TestCase ...@@ -317,8 +317,13 @@ class AttachmentTest < Test::Unit::TestCase
before_should "call #make on all specified processors" do before_should "call #make on all specified processors" do
expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => nil, :convert_options => ""}) expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => nil, :convert_options => ""})
Paperclip::Thumbnail.expects(:make).with(@file, expected_params).returns(@file) Paperclip::Thumbnail.expects(:make).with(@file, expected_params, @dummy.avatar).returns(@file)
Paperclip::Test.expects(:make).with(@file, expected_params).returns(@file) Paperclip::Test.expects(:make).with(@file, expected_params, @dummy.avatar).returns(@file)
end
before_should "call #make with attachment passed as third argument" do
expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => nil, :convert_options => ""})
Paperclip::Test.expects(:make).with(@file, expected_params, @dummy.avatar).returns(@file)
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment