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

allow proc for fog_host

parent e049ec53
......@@ -126,7 +126,12 @@ module Paperclip
def public_url(style = default_style)
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)}"
else
if fog_credentials[:provider] == 'AWS'
......
......@@ -229,11 +229,25 @@ class FogTest < Test::Unit::TestCase
@dummy.avatar = @file
@dummy.save
end
should "have created the bucket" do
assert @connection.directories.get(@dynamic_fog_directory).inspect
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
......
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