Commit aa6338a9 by Jon Yurek

:s3_host_name can be a proc

parent 29bb5643
...@@ -172,7 +172,10 @@ module Paperclip ...@@ -172,7 +172,10 @@ module Paperclip
end end
def s3_host_name def s3_host_name
@options[:s3_host_name] || s3_credentials[:s3_host_name] || "s3.amazonaws.com" host_name = @options[:s3_host_name]
host_name = host_name.call(self) if host_name.is_a?(Proc)
host_name || s3_credentials[:s3_host_name] || "s3.amazonaws.com"
end end
def s3_host_alias def s3_host_alias
......
...@@ -238,6 +238,26 @@ class S3Test < Test::Unit::TestCase ...@@ -238,6 +238,26 @@ class S3Test < Test::Unit::TestCase
end end
end end
context "dynamic s3_host_name" do
setup do
rebuild_model :storage => :s3,
:s3_credentials => {},
:bucket => "bucket",
:path => ":attachment/:basename.:extension",
:s3_host_name => lambda {|a| a.instance.value }
@dummy = Dummy.new
class << @dummy
attr_accessor :value
end
@dummy.avatar = StringIO.new(".")
end
should "use s3_host_name as a proc if available" do
@dummy.value = "s3.something.com"
assert_equal "http://s3.something.com/bucket/avatars/stringio.txt", @dummy.avatar.url(:original, :timestamp => false)
end
end
context "An attachment that uses S3 for storage and has styles that return different file types" do context "An attachment that uses S3 for storage and has styles that return different file types" do
setup do setup do
rebuild_model :styles => { :large => ['500x500#', :jpg] }, rebuild_model :styles => { :large => ['500x500#', :jpg] },
......
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