Sha256: 15cd2d5f70aee9a18e87452689cc4e444c71062946faa7983ff3410335aa22cd

Contents?: true

Size: 979 Bytes

Versions: 1

Compression:

Stored size: 979 Bytes

Contents

module Paperclip
  module Storage
    module S3
      # Mixin which interfaces with the 'aws' and 'right_aws' libraries.
      module AwsLibrary
        protected

        def s3_connect!
          @s3 = Aws::S3.new(
            @s3_credentials[:access_key_id],
            @s3_credentials[:secret_access_key]
          )
          @s3_bucket = @s3.bucket(bucket_name)
        end

        def s3_expiring_url(key,time)
          @s3.interface.get_link(bucket_name,key,time)
        end

        def s3_exists?(key)
          @s3_bucket.keys(:prefix => key).any? { |s3_key| s3_key.name == key }
        end

        def s3_download(key,file)
          @s3_bucket.key(key).get { |chunk| file.write(chunk) }
        end

        def s3_store(key,file)
          @s3_bucket.key(key).put(
            file,
            @s3_permissions.to_s.gsub('_','-')
          )
        end

        def s3_delete(key)
          @s3_bucket.key(key).delete
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-paperclip-2.5.0 lib/dm-paperclip/storage/s3/aws_library.rb