Commit 2b562a9b by Benjamin Hüttinger Committed by Benjamin Hüttinger

allow proc for fog_host

parent e049ec53
...@@ -126,7 +126,12 @@ module Paperclip ...@@ -126,7 +126,12 @@ module Paperclip
def public_url(style = default_style) def public_url(style = default_style)
if @options[:fog_host] if @options[:fog_host]
host = (@options[:fog_host] =~ /%d/) ? @options[:fog_host] % (path(style).hash % 4) : @options[:fog_host] host = if @options[:fog_host].is_a?(Proc)
@options[:fog_host].call(self)
else
(@options[:fog_host] =~ /%d/) ? @options[:fog_host] % (path(style).hash % 4) : @options[:fog_host]
end
"#{host}/#{path(style)}" "#{host}/#{path(style)}"
else else
if fog_credentials[:provider] == 'AWS' if fog_credentials[:provider] == 'AWS'
......
...@@ -235,6 +235,20 @@ class FogTest < Test::Unit::TestCase ...@@ -235,6 +235,20 @@ class FogTest < Test::Unit::TestCase
end end
end end
context "with a proc for the fog_host evaluating a model method" do
setup do
rebuild_model(@options.merge(:fog_host => lambda { |attachment| attachment.instance.fog_host }))
@dummy = Dummy.new
@dummy.stubs(:fog_host).returns('http://dynamicfoghost.com')
@dummy.avatar = @file
@dummy.save
end
should "provide a public url" do
assert_match /http:\/\/dynamicfoghost\.com/, @dummy.avatar.url
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