Class: S3Lib::Bucket
- Inherits:
-
Object
- Object
- S3Lib::Bucket
- Defined in:
- lib/service_dev.rb,
lib/bucket_find.rb,
lib/bucket_create.rb
Overview
This is a stub of the Bucket class that will be replaced with a full-blown class in the following recipes.
Instance Attribute Summary collapse
-
#marker ⇒ Object
readonly
Returns the value of attribute marker.
-
#max_keys ⇒ Object
readonly
Returns the value of attribute max_keys.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Class Method Summary collapse
-
.create(name, params = {}) ⇒ Object
Todo: Class methods Bucket::find Bucket::delete (have :force => true) Bucket::delete_all_objects Bucket::objects Bucket::new instance methods Bucket#objects Bucket#delete Bucket#delete_all_objects Bucket#each.
- .find(name, params = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(doc) ⇒ Bucket
constructor
A new instance of Bucket.
- #is_truncated? ⇒ Boolean
- #objects ⇒ Object
Constructor Details
#initialize(doc) ⇒ Bucket
Returns a new instance of Bucket.
17 18 19 20 21 22 23 |
# File 'lib/bucket_find.rb', line 17 def initialize(doc) @xml = doc.root @name = @xml.elements['Name'].text @max_keys = @xml.elements['MaxKeys'].text.to_i @prefix = @xml.elements['Prefix'].text @marker = @xml.elements['Marker'].text end |
Instance Attribute Details
#marker ⇒ Object (readonly)
Returns the value of attribute marker.
9 10 11 |
# File 'lib/bucket_find.rb', line 9 def marker @marker end |
#max_keys ⇒ Object (readonly)
Returns the value of attribute max_keys.
9 10 11 |
# File 'lib/bucket_find.rb', line 9 def max_keys @max_keys end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/service_dev.rb', line 24 def name @name end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/bucket_find.rb', line 9 def prefix @prefix end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
9 10 11 |
# File 'lib/bucket_find.rb', line 9 def xml @xml end |
Class Method Details
.create(name, params = {}) ⇒ Object
Todo: Class methods Bucket::find Bucket::delete (have :force => true) Bucket::delete_all_objects Bucket::objects Bucket::new instance methods Bucket#objects Bucket#delete Bucket#delete_all_objects Bucket#each
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bucket_create.rb', line 23 def self.create(name, params = {}) params['x-amz-acl'] = params.delete(:access) if params[:access] # translate from :access to 'x-amz-acl' begin response = S3Lib.request(:put, name, params) rescue S3Lib::S3ResponseError => error if error.amazon_error_type == "BucketAlreadyExists" raise S3Lib::NotYourBucketError.new("The bucket '#{name}' is already owned by somebody else", error.io, error.s3requester) else raise # re-raise the exception if it's not a BucketAlreadyExists error end end response.status[0] == "200" ? true : false end |
Instance Method Details
#is_truncated? ⇒ Boolean
25 26 27 |
# File 'lib/bucket_find.rb', line 25 def is_truncated? @xml.elements['IsTruncated'].text == 'true' end |
#objects ⇒ Object
29 30 31 32 33 |
# File 'lib/bucket_find.rb', line 29 def objects REXML::XPath.match(@xml, '//Contents').collect do |object| S3Lib::S3Object.new(object) end end |