Commit 0f47993c by Jon Yurek

Moved the business of interpolation into the interpolations module

parent 04140e5a
......@@ -388,12 +388,7 @@ module Paperclip
end
def interpolate pattern, style = default_style #:nodoc:
interpolations = Paperclip::Interpolations.all
interpolations.reverse.inject( pattern.dup ) do |result, tag|
result.gsub(/:#{tag}/) do |match|
Paperclip::Interpolations.send( tag, self, style )
end
end
Paperclip::Interpolations.interpolate(pattern, self, style)
end
def queue_existing_for_delete #:nodoc:
......
......@@ -14,6 +14,14 @@ module Paperclip
self.instance_methods(false).sort
end
def self.interpolate pattern, *args
all.reverse.inject( pattern.dup ) do |result, tag|
result.gsub(/:#{tag}/) do |match|
send( tag, *args )
end
end
end
def rails_root attachment, style
RAILS_ROOT
end
......
......@@ -75,4 +75,12 @@ class InterpolationsTest < Test::Unit::TestCase
attachment.expects(:default_style).returns(:default_style)
assert_equal :default_style, Paperclip::Interpolations.style(attachment, nil)
end
should "call all expected interpolations with the given arguments" do
Paperclip::Interpolations.expects(:id).with(:attachment, :style).returns(1234)
Paperclip::Interpolations.expects(:attachment).with(:attachment, :style).returns("attachments")
Paperclip::Interpolations.expects(:notreal).never
value = Paperclip::Interpolations.interpolate(":notreal/:id/:attachment", :attachment, :style)
assert_equal ":notreal/1234/attachments", value
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