lib/paperclip/storage.rb in thoughtbot-paperclip-2.2.8 vs lib/paperclip/storage.rb in thoughtbot-paperclip-2.2.9.1

- old
+ new

@@ -37,21 +37,21 @@ def flush_writes #:nodoc: @queued_for_write.each do |style, file| file.close FileUtils.mkdir_p(File.dirname(path(style))) - logger.info("[paperclip] saving #{path(style)}") + log("saving #{path(style)}") FileUtils.mv(file.path, path(style)) FileUtils.chmod(0644, path(style)) end @queued_for_write = {} end def flush_deletes #:nodoc: @queued_for_delete.each do |path| begin - logger.info("[paperclip] deleting #{path}") + log("deleting #{path}") FileUtils.rm(path) if File.exist?(path) rescue Errno::ENOENT => e # ignore file-not-found, let everything else pass end begin @@ -60,11 +60,11 @@ FileUtils.rmdir(path) end rescue Errno::EEXIST, Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR # Stop trying to remove parent directories rescue SystemCallError => e - logger.info("[paperclip] There was an unexpected error while deleting directories: #{e.class}") + log("There was an unexpected error while deleting directories: #{e.class}") # Ignore it end end @queued_for_delete = [] end @@ -126,10 +126,12 @@ # to interpolate. Keys should be unique, like filenames, and despite the fact that # S3 (strictly speaking) does not support directories, you can still use a / to # separate parts of your file name. module S3 def self.extended base + warn('[DEPRECATION] S3 support through RightAWS is deprecated. S3 support will ' + + 'be changed to AWS::S3 in a future version.') require 'right_aws' base.instance_eval do @s3_credentials = parse_credentials(@options[:s3_credentials]) @bucket = @options[:bucket] || @s3_credentials[:bucket] @bucket = @bucket.call(self) if @bucket.is_a?(Proc) @@ -138,17 +140,17 @@ @s3_protocol = @options[:s3_protocol] || (@s3_permissions == 'public-read' ? 'http' : 'https') @s3_headers = @options[:s3_headers] || {} @s3_host_alias = @options[:s3_host_alias] @url = ":s3_path_url" unless @url.to_s.match(/^:s3.*url$/) end - base.class.interpolations[:s3_alias_url] = lambda do |attachment, style| + Paperclip.interpolates(:s3_alias_url) do |attachment, style| "#{attachment.s3_protocol}://#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}" end - base.class.interpolations[:s3_path_url] = lambda do |attachment, style| + Paperclip.interpolates(:s3_path_url) do |attachment, style| "#{attachment.s3_protocol}://s3.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}" end - base.class.interpolations[:s3_domain_url] = lambda do |attachment, style| + Paperclip.interpolates(:s3_domain_url) do |attachment, style| "#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}" end end def s3 @@ -169,11 +171,11 @@ @s3_host_alias end def parse_credentials creds creds = find_credentials(creds).stringify_keys - (creds[ENV['RAILS_ENV']] || creds).symbolize_keys + (creds[RAILS_ENV] || creds).symbolize_keys end def exists?(style = default_style) s3_bucket.key(path(style)) ? true : false end @@ -190,11 +192,11 @@ alias_method :to_io, :to_file def flush_writes #:nodoc: @queued_for_write.each do |style, file| begin - logger.info("[paperclip] saving #{path(style)}") + log("saving #{path(style)}") key = s3_bucket.key(path(style)) key.data = file key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)}.merge(@s3_headers)) rescue RightAws::AwsError => e raise @@ -204,10 +206,10 @@ end def flush_deletes #:nodoc: @queued_for_delete.each do |path| begin - logger.info("[paperclip] deleting #{path}") + log("deleting #{path}") if file = s3_bucket.key(path) file.delete end rescue RightAws::AwsError # Ignore this.