Class: S3Light::Bucket
- Inherits:
-
Struct
- Object
- Struct
- S3Light::Bucket
- Defined in:
- lib/s3-light/bucket.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#name ⇒ Object
Returns the value of attribute name.
-
#persisted ⇒ Object
Returns the value of attribute persisted.
Instance Method Summary collapse
- #__destroy!(connection) ⇒ Object
- #__save!(connection) ⇒ Object
- #destroy! ⇒ Object
-
#initialize(client, name, persisted = false) ⇒ Bucket
constructor
A new instance of Bucket.
- #inspect ⇒ Object
- #objects ⇒ Object
- #persisted? ⇒ Boolean
- #save! ⇒ Object
Constructor Details
#initialize(client, name, persisted = false) ⇒ Bucket
Returns a new instance of Bucket.
5 6 7 |
# File 'lib/s3-light/bucket.rb', line 5 def initialize(client, name, persisted = false) super(client, name, persisted) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client
4 5 6 |
# File 'lib/s3-light/bucket.rb', line 4 def client @client end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/s3-light/bucket.rb', line 4 def name @name end |
#persisted ⇒ Object
Returns the value of attribute persisted
4 5 6 |
# File 'lib/s3-light/bucket.rb', line 4 def persisted @persisted end |
Instance Method Details
#__destroy!(connection) ⇒ Object
45 46 47 |
# File 'lib/s3-light/bucket.rb', line 45 def __destroy!(connection) connection.make_request(:delete, "/#{name}") end |
#__save!(connection) ⇒ Object
49 50 51 |
# File 'lib/s3-light/bucket.rb', line 49 def __save!(connection) connection.make_request(:put, "/#{name}") end |
#destroy! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/s3-light/bucket.rb', line 26 def destroy! unless persisted raise S3Light::Error, 'Bucket does not exist' end self.client.with_connection do |connection| __destroy!(connection) rescue S3Light::Connection::HttpError => e raise e unless e.code == 404 end self.persisted = false true end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/s3-light/bucket.rb', line 57 def inspect "#<#{self.class.name} @name=#{name} @persisted=#{persisted}>" end |
#objects ⇒ Object
41 42 43 |
# File 'lib/s3-light/bucket.rb', line 41 def objects @objects ||= S3Light::Client::ObjectsList.new(client, self) end |
#persisted? ⇒ Boolean
53 54 55 |
# File 'lib/s3-light/bucket.rb', line 53 def persisted? persisted end |
#save! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/s3-light/bucket.rb', line 9 def save! if persisted raise S3Light::Error, 'Bucket already exists' end if name.nil? || name.empty? raise S3Light::Error, 'Bucket name is required' end self.client.with_connection do |connection| __save!(connection) end self.persisted = true self end |