Permalink
Browse files

allow proc for fog_directory so its possible to call model methods to…

… set the directory
  • Loading branch information...
1 parent 65e0338 commit e049ec5337e9aa0ae904bf64d3ab38793d30f8cd @maxigs maxigs committed with maxigs Jan 19, 2012
Showing with 22 additions and 1 deletion.
  1. +7 −1 lib/paperclip/storage/fog.rb
  2. +15 −0 test/storage/fog_test.rb
@@ -168,7 +168,13 @@ def connection
end
def directory
- @directory ||= connection.directories.new(:key => @options[:fog_directory])
+ dir = if @options[:fog_directory].is_a?(Proc)
+ @options[:fog_directory].call(self)
+ else
+ @options[:fog_directory]
+ end
+
+ @directory ||= connection.directories.new(:key => dir)
end
end
end
View
@@ -220,6 +220,21 @@ class FogTest < Test::Unit::TestCase
end
+ context "with a proc for a bucket name evaluating a model method" do
+ setup do
+ @dynamic_fog_directory = 'dynamicpaperclip'
+ rebuild_model(@options.merge(:fog_directory => lambda { |attachment| attachment.instance.bucket_name }))
+ @dummy = Dummy.new
+ @dummy.stubs(:bucket_name).returns(@dynamic_fog_directory)
+ @dummy.avatar = @file
+ @dummy.save
+ end
+
+ should "have created the bucket" do
+ assert @connection.directories.get(@dynamic_fog_directory).inspect
+ end
+
+ end
end
end

0 comments on commit e049ec5

Please sign in to comment.