class HasBucket::Facade

Public Class Methods

new(service, bucket_name) click to toggle source
# File lib/has_bucket/facade.rb, line 8
def initialize(service, bucket_name)
  @service = service
  @bucket_name = bucket_name
end

Public Instance Methods

[](key) click to toggle source
# File lib/has_bucket/facade.rb, line 33
def [](key)
  object(key).content
end
[]=(key, content) click to toggle source
# File lib/has_bucket/facade.rb, line 25
def []=(key, content)
  s3_object = object(key)
  s3_object.acl = "private"
  s3_object.content_type = content_type_from_key(key)
  s3_object.content = content
  s3_object.save
end
delete(key) click to toggle source
# File lib/has_bucket/facade.rb, line 45
def delete(key)
  object(key).destroy
end
include?(key) click to toggle source
# File lib/has_bucket/facade.rb, line 13
def include?(key)
  object(key).exists?
end
object_keys() click to toggle source
# File lib/has_bucket/facade.rb, line 17
def object_keys
  bucket.objects.map(&:key)
end
prefixed_with(prefix) click to toggle source
# File lib/has_bucket/facade.rb, line 21
def prefixed_with(prefix)
  bucket.objects(:prefix => prefix).map(&:key)
end
public_url_for(key) click to toggle source
# File lib/has_bucket/facade.rb, line 41
def public_url_for(key)
  object(key).url
end
url_for(key, expiring_at = Time.now + 3600) click to toggle source
# File lib/has_bucket/facade.rb, line 37
def url_for(key, expiring_at = Time.now + 3600)
  object(key).temporary_url(expiring_at)
end

Private Instance Methods

bucket() click to toggle source
# File lib/has_bucket/facade.rb, line 55
def bucket
  @service.bucket(@bucket_name)
end
content_type_from_key(key) click to toggle source
# File lib/has_bucket/facade.rb, line 59
def content_type_from_key(key)
  if (mime_type = MIME::Types.of(key).find { |mime| !mime.obsolete? })
    mime_type.content_type
  else
    "application/octet-stream"
  end
end
object(key) click to toggle source
# File lib/has_bucket/facade.rb, line 51
def object(key)
  bucket.object(key)
end