Browse files

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

(cherry picked from commit e655fbe502fbae2b538922b35c6d2f55b1fee3d1)
  • Loading branch information...
1 parent 35b912a commit 2fda5b1069c368d81954d2c3dc2589a7e1a94288 @szajbus szajbus committed with jyurek Feb 6, 2009
Showing with 14 additions and 8 deletions.
  1. +1 −1 lib/paperclip/attachment.rb
  2. +5 −4 lib/paperclip/processor.rb
  3. +1 −1 lib/paperclip/thumbnail.rb
  4. +7 −2 test/attachment_test.rb
View
2 lib/paperclip/attachment.rb
@@ -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}")
View
9 lib/paperclip/processor.rb
@@ -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
View
2 lib/paperclip/thumbnail.rb
@@ -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
View
9 test/attachment_test.rb
@@ -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

0 comments on commit 2fda5b1

Please sign in to comment.