class ContentCaching::Adapter::Aws

Constants

T_1_DAY

Attributes

options[R]

Public Class Methods

new(options) click to toggle source
# File lib/content_caching/adapters/aws.rb, line 12
def initialize options
  @options = options
end

Public Instance Methods

delete(document_path) click to toggle source
# File lib/content_caching/adapters/aws.rb, line 28
def delete document_path
  retryable(3) do
    bucket.object(document_path).delete
  end
end
store(document_path, content) click to toggle source
# File lib/content_caching/adapters/aws.rb, line 16
def store document_path, content
  retryable(3) do
    content.rewind if content.respond_to?(:rewind)
    bucket.put_object key: document_path,
      body: (content.respond_to?(:read) ? content.read : content)
  end
end
url(document_path) click to toggle source
# File lib/content_caching/adapters/aws.rb, line 24
def url document_path
  bucket.object(document_path).presigned_url :get, expires_in: T_1_DAY
end

Private Instance Methods

aws_credentials() click to toggle source
# File lib/content_caching/adapters/aws.rb, line 43
def aws_credentials
 :: Aws::Credentials.new self.options[:aws_access_key_id],
                       self.options[:aws_secret_access_key]
end
bucket() click to toggle source
# File lib/content_caching/adapters/aws.rb, line 36
def bucket
  ::Aws::S3::Resource.new(
    credentials: aws_credentials,
    region: self.options[:region]
  ).bucket self.options[:directory]
end