Commit 95acf3b8 by Tute Costa

Merge pull request #2093 from gatherdigital/dynamic-fog-directory

Bugfix: Dynamic fog directory
parents 0ae039d2 84a5d41c
* Bugfix: Dynamic fog directory option is now respected
5.0.0.beta1 5.0.0.beta1
* Drop support to end-of-life'd ruby 2.0. * Drop support to end-of-life'd ruby 2.0.
......
...@@ -195,10 +195,10 @@ module Paperclip ...@@ -195,10 +195,10 @@ module Paperclip
end end
def host_name_for_directory def host_name_for_directory
if @options[:fog_directory].to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX if directory_name.to_s =~ Fog::AWS_BUCKET_SUBDOMAIN_RESTRICTON_REGEX
"#{@options[:fog_directory]}.s3.amazonaws.com" "#{directory_name}.s3.amazonaws.com"
else else
"s3.amazonaws.com/#{@options[:fog_directory]}" "s3.amazonaws.com/#{directory_name}"
end end
end end
...@@ -224,13 +224,15 @@ module Paperclip ...@@ -224,13 +224,15 @@ module Paperclip
end end
def directory def directory
dir = if @options[:fog_directory].respond_to?(:call) @directory ||= connection.directories.new(key: directory_name)
end
def directory_name
if @options[:fog_directory].respond_to?(:call)
@options[:fog_directory].call(self) @options[:fog_directory].call(self)
else else
@options[:fog_directory] @options[:fog_directory]
end end
@directory ||= connection.directories.new(:key => dir)
end end
def scheme def scheme
......
...@@ -418,6 +418,9 @@ describe Paperclip::Storage::Fog do ...@@ -418,6 +418,9 @@ describe Paperclip::Storage::Fog do
assert @connection.directories.get(@dynamic_fog_directory).inspect assert @connection.directories.get(@dynamic_fog_directory).inspect
end end
it "provides an url using dynamic bucket name" do
assert_match(/^https:\/\/dynamicpaperclip.s3.amazonaws.com\/avatars\/5k.png\?\d*$/, @dummy.avatar.url)
end
end end
context "with a proc for the fog_host evaluating a model method" do context "with a proc for the fog_host evaluating a model method" do
......
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