Skip to content

Commit

Permalink
Now Attachment instance is passed as third argument to Processor#make.
Browse files Browse the repository at this point in the history
(cherry picked from commit e655fbe502fbae2b538922b35c6d2f55b1fee3d1)
  • Loading branch information
szajbus authored and Jon Yurek committed Feb 8, 2009
1 parent 35b912a commit 2fda5b1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/paperclip/attachment.rb
Expand Up @@ -359,7 +359,7 @@ def post_process_styles
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|
log("Processing #{name} #{file} in the #{processor} processor.")
Paperclip.processor(processor).make(file, args)
Paperclip.processor(processor).make(file, args, self)
end
rescue PaperclipError => e
log("An error was received while processing: #{e.inspect}")
Expand Down
9 changes: 5 additions & 4 deletions lib/paperclip/processor.rb
Expand Up @@ -17,18 +17,19 @@ module Paperclip
# See Paperclip.run for more information about using command-line
# utilities from within Processors.
class Processor
attr_accessor :file, :options
attr_accessor :file, :options, :attachment

def initialize file, options = {}
def initialize file, options = {}, attachment = nil
@file = file
@options = options
@attachment = attachment
end

def make
end

def self.make file, options = {}
new(file, options).make
def self.make file, options = {}, attachment = nil
new(file, options, attachment).make
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/thumbnail.rb
Expand Up @@ -10,7 +10,7 @@ class Thumbnail < Processor
# unless specified. Thumbnail creation will raise no errors unless
# +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
def initialize file, options = {}
def initialize file, options = {}, attachment = nil
super
geometry = options[:geometry]
@file = file
Expand Down
9 changes: 7 additions & 2 deletions test/attachment_test.rb
Expand Up @@ -317,8 +317,13 @@ class Paperclip::Test < Paperclip::Processor; end

before_should "call #make on all specified processors" do
expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => nil, :convert_options => ""})
Paperclip::Thumbnail.expects(:make).with(@file, expected_params).returns(@file)
Paperclip::Test.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, @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
Expand Down

0 comments on commit 2fda5b1

Please sign in to comment.