Permalink
Browse files

allow proc for fog_host

  • Loading branch information...
1 parent e049ec5 commit 2b562a9be16d2398fec7f3d80685b8c8a199e655 @maxigs maxigs committed with maxigs Jan 19, 2012
Showing with 22 additions and 3 deletions.
  1. +6 −1 lib/paperclip/storage/fog.rb
  2. +16 −2 test/storage/fog_test.rb
@@ -126,7 +126,12 @@ def to_file(style = default_style)
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'
View
@@ -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

0 comments on commit 2b562a9

Please sign in to comment.