Commit 0f47993c by Jon Yurek

Moved the business of interpolation into the interpolations module

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