Permalink
Browse files

Refactor previous: move complexity into s3_permissions method

  • Loading branch information...
1 parent 5ce04ed commit 45e4b075419b3ce2f10f1c53cc2bc6936f3e4c55 @jyurek jyurek committed May 18, 2012
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/paperclip/storage/s3.rb
@@ -150,16 +150,13 @@ def sanitize_hash(hash)
end
Paperclip.interpolates(:s3_alias_url) do |attachment, style|
- url_prefix = (s3_protocol = attachment.s3_protocol(style)).present? ? "#{s3_protocol}:" : ""
- "#{url_prefix}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
+ "#{attachment.s3_protocol(style)}//#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_alias_url
Paperclip.interpolates(:s3_path_url) do |attachment, style|
- url_prefix = (s3_protocol = attachment.s3_protocol(style)).present? ? "#{s3_protocol}:" : ""
- "#{url_prefix}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
+ "#{attachment.s3_protocol(style)}//#{attachment.s3_host_name}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_path_url
Paperclip.interpolates(:s3_domain_url) do |attachment, style|
- url_prefix = (s3_protocol = attachment.s3_protocol(style)).present? ? "#{s3_protocol}:" : ""
- "#{url_prefix}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
+ "#{attachment.s3_protocol(style)}//#{attachment.bucket_name}.#{attachment.s3_host_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
end unless Paperclip::Interpolations.respond_to? :s3_domain_url
Paperclip.interpolates(:asset_host) do |attachment, style|
"#{attachment.path(style).gsub(%r{^/}, "")}"
@@ -284,11 +281,14 @@ def s3_permissions(style = default_style)
end
def s3_protocol(style = default_style)
- if @s3_protocol.is_a?(Proc)
+ protocol = if @s3_protocol.is_a?(Proc)
@s3_protocol.call(style, self)
else
@s3_protocol
end
+
+ protocol = protocol.split(":").first + ":" unless protocol.empty?
+ protocol
end
def create_bucket
@@ -360,7 +360,7 @@ def find_credentials creds
private :find_credentials
def use_secure_protocol?(style_name)
- s3_protocol(style_name) == "https"
+ s3_protocol(style_name) == "https:"
end
private :use_secure_protocol?
end

0 comments on commit 45e4b07

Please sign in to comment.