Commit 45e4b075 by Jon Yurek

Refactor previous: move complexity into s3_permissions method

parent 5ce04edb
...@@ -150,16 +150,13 @@ module Paperclip ...@@ -150,16 +150,13 @@ module Paperclip
end end
Paperclip.interpolates(:s3_alias_url) do |attachment, style| Paperclip.interpolates(:s3_alias_url) do |attachment, style|
url_prefix = (s3_protocol = attachment.s3_protocol(style)).present? ? "#{s3_protocol}:" : "" "#{attachment.s3_protocol(style)}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{url_prefix}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_alias_url end unless Paperclip::Interpolations.respond_to? :s3_alias_url
Paperclip.interpolates(:s3_path_url) do |attachment, style| Paperclip.interpolates(:s3_path_url) do |attachment, style|
url_prefix = (s3_protocol = attachment.s3_protocol(style)).present? ? "#{s3_protocol}:" : "" "#{attachment.s3_protocol(style)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{url_prefix}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_path_url end unless Paperclip::Interpolations.respond_to? :s3_path_url
Paperclip.interpolates(:s3_domain_url) do |attachment, style| Paperclip.interpolates(:s3_domain_url) do |attachment, style|
url_prefix = (s3_protocol = attachment.s3_protocol(style)).present? ? "#{s3_protocol}:" : "" "#{attachment.s3_protocol(style)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
"#{url_prefix}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_domain_url end unless Paperclip::Interpolations.respond_to? :s3_domain_url
Paperclip.interpolates(:asset_host) do |attachment, style| Paperclip.interpolates(:asset_host) do |attachment, style|
"#{attachment.path(style).gsub(%r{^/}, "")}" "#{attachment.path(style).gsub(%r{^/}, "")}"
...@@ -284,11 +281,14 @@ module Paperclip ...@@ -284,11 +281,14 @@ module Paperclip
end end
def s3_protocol(style = default_style) def s3_protocol(style = default_style)
if @s3_protocol.is_a?(Proc) protocol = if @s3_protocol.is_a?(Proc)
@s3_protocol.call(style, self) @s3_protocol.call(style, self)
else else
@s3_protocol @s3_protocol
end end
protocol = protocol.split(":").first + ":" unless protocol.empty?
protocol
end end
def create_bucket def create_bucket
...@@ -360,7 +360,7 @@ module Paperclip ...@@ -360,7 +360,7 @@ module Paperclip
private :find_credentials private :find_credentials
def use_secure_protocol?(style_name) def use_secure_protocol?(style_name)
s3_protocol(style_name) == "https" s3_protocol(style_name) == "https:"
end end
private :use_secure_protocol? private :use_secure_protocol?
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