Commit 92e88fc3 by Pavel Pravosud Committed by Jon Yurek

Added a feature to evaluate lambdas for fog_file properties

parent 446a4cdb
...@@ -66,7 +66,16 @@ module Paperclip ...@@ -66,7 +66,16 @@ module Paperclip
end end
def fog_file def fog_file
@fog_file ||= @options[:fog_file] || {} @fog_file ||= begin
value = @options[:fog_file]
if !value
{}
elsif value.respond_to?(:call)
value.call(self)
else
value
end
end
end end
def fog_public(style = default_style) def fog_public(style = default_style)
......
...@@ -90,6 +90,27 @@ class FogTest < Test::Unit::TestCase ...@@ -90,6 +90,27 @@ class FogTest < Test::Unit::TestCase
end end
end end
context "with file params provided as lambda" do
setup do
fog_file = lambda{ |a| { :custom_header => a.instance.custom_method }}
klass = rebuild_model :storage => :fog,
:fog_file => fog_file
klass.class_eval do
def custom_method
'foobar'
end
end
@dummy = Dummy.new
end
should "be able to evaluate correct values for file headers" do
assert_equal @dummy.avatar.send(:fog_file), { :custom_header => 'foobar' }
end
end
setup do setup do
@fog_directory = 'papercliptests' @fog_directory = 'papercliptests'
......
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