mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
77 lines
1.6 KiB
Ruby
77 lines
1.6 KiB
Ruby
module Fog
|
|
module AWS
|
|
class S3
|
|
|
|
class Bucket < Fog::Model
|
|
|
|
attribute :creation_date, 'CreationDate'
|
|
attribute :location
|
|
attribute :name, 'Name'
|
|
attribute :owner
|
|
|
|
def initialize(attributes = {})
|
|
super
|
|
end
|
|
|
|
def buckets
|
|
@buckets
|
|
end
|
|
|
|
def destroy
|
|
connection.delete_bucket(@name)
|
|
buckets.delete(name)
|
|
true
|
|
rescue Fog::Errors::NotFound
|
|
false
|
|
end
|
|
|
|
def location
|
|
data = connection.get_bucket_location(@name)
|
|
data.body['LocationConstraint']
|
|
end
|
|
|
|
def objects
|
|
@objects ||= begin
|
|
Fog::AWS::S3::Objects.new(
|
|
:bucket => self,
|
|
:connection => connection
|
|
)
|
|
end
|
|
end
|
|
|
|
def payer
|
|
data = connection.get_request_payment(@name)
|
|
data.body['Payer']
|
|
end
|
|
|
|
def payer=(new_payer)
|
|
connection.put_request_payment(@name, new_payer)
|
|
@payer = new_payer
|
|
end
|
|
|
|
def reload
|
|
new_attributes = buckets.get(@name).attributes
|
|
merge_attributes(new_attributes)
|
|
end
|
|
|
|
def save
|
|
options = {}
|
|
if @location
|
|
options['LocationConstraint'] = @location
|
|
end
|
|
connection.put_bucket(@name, options)
|
|
buckets[name] = self
|
|
true
|
|
end
|
|
|
|
private
|
|
|
|
def buckets=(new_buckets)
|
|
@buckets = new_buckets
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|