2010-03-13 13:37:24 -08:00
|
|
|
require 'fog/model'
|
|
|
|
require 'fog/aws/models/s3/files'
|
|
|
|
|
2009-08-02 16:37:54 -07:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-03-13 13:37:24 -08:00
|
|
|
module S3
|
2009-08-02 16:37:54 -07:00
|
|
|
|
2010-01-14 20:44:39 -08:00
|
|
|
class Directory < Fog::Model
|
2009-08-02 16:37:54 -07:00
|
|
|
|
2009-10-23 10:27:23 -07:00
|
|
|
identity :name, 'Name'
|
|
|
|
|
2009-08-30 14:43:01 -07:00
|
|
|
attribute :creation_date, 'CreationDate'
|
2009-08-04 10:51:54 -07:00
|
|
|
|
2009-08-30 14:14:11 -07:00
|
|
|
def destroy
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :name
|
2009-09-02 20:17:53 -07:00
|
|
|
connection.delete_bucket(@name)
|
2009-08-27 20:47:01 -07:00
|
|
|
true
|
2009-11-08 12:16:52 -08:00
|
|
|
rescue Excon::Errors::NotFound
|
2009-08-31 22:40:07 -07:00
|
|
|
false
|
2009-08-03 22:50:52 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def location
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :name
|
2009-09-04 17:25:41 -07:00
|
|
|
data = connection.get_bucket_location(@name)
|
2009-09-02 20:17:53 -07:00
|
|
|
data.body['LocationConstraint']
|
2009-08-03 22:50:52 -07:00
|
|
|
end
|
|
|
|
|
2009-10-23 09:42:51 -07:00
|
|
|
def location=(new_location)
|
|
|
|
@location = new_location
|
|
|
|
end
|
|
|
|
|
2010-01-14 20:44:39 -08:00
|
|
|
def files
|
|
|
|
@files ||= begin
|
|
|
|
Fog::AWS::S3::Files.new(
|
|
|
|
:directory => self,
|
2009-09-01 21:41:52 -07:00
|
|
|
:connection => connection
|
|
|
|
)
|
|
|
|
end
|
2009-08-12 22:48:17 -07:00
|
|
|
end
|
|
|
|
|
2009-08-03 22:50:52 -07:00
|
|
|
def payer
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :name
|
2009-09-02 20:17:53 -07:00
|
|
|
data = connection.get_request_payment(@name)
|
|
|
|
data.body['Payer']
|
2009-08-03 22:50:52 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def payer=(new_payer)
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :name
|
2009-09-02 20:17:53 -07:00
|
|
|
connection.put_request_payment(@name, new_payer)
|
2009-08-03 22:54:34 -07:00
|
|
|
@payer = new_payer
|
2009-08-03 22:50:52 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2009-11-21 13:56:39 -08:00
|
|
|
requires :name
|
2009-08-03 22:50:52 -07:00
|
|
|
options = {}
|
|
|
|
if @location
|
|
|
|
options['LocationConstraint'] = @location
|
|
|
|
end
|
2009-09-02 20:17:53 -07:00
|
|
|
connection.put_bucket(@name, options)
|
2009-08-27 20:47:01 -07:00
|
|
|
true
|
2009-08-03 22:50:52 -07:00
|
|
|
end
|
2009-08-02 16:37:54 -07:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|