Commit e049ec53 by Benjamin Hüttinger Committed by Benjamin Hüttinger

allow proc for fog_directory so its possible to call model methods to set the directory

parent 65e0338f
...@@ -168,7 +168,13 @@ module Paperclip ...@@ -168,7 +168,13 @@ module Paperclip
end end
def directory 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 end
end end
......
...@@ -220,6 +220,21 @@ class FogTest < Test::Unit::TestCase ...@@ -220,6 +220,21 @@ class FogTest < Test::Unit::TestCase
end 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
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