Class: S33r::Bucket
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Client
#access, #canned_acl, #created_with_options, #expires, #secret, #subdomain, #use_ssl
Instance Method Summary collapse
-
#[](key, load_object = true) ⇒ Object
Get an object from S3.
-
#delete(key, options = {}) ⇒ Object
Delete a key from inside the bucket.
-
#destroy(options = {}) ⇒ Object
Destroy this bucket.
- #exists? ⇒ Boolean
-
#initialize(bucket_name, options = {}) {|_self| ... } ⇒ Bucket
constructor
options
: *:check => true
: if setting a :bucket option, the default behaviour is not to check whether the bucket actually exists on S3. -
#keys(options = {}) ⇒ Object
List of keys in the bucket.
-
#log_receiver(state = :on) ⇒ Object
Change whether the bucket can be used to receive logs.
-
#log_receiver? ⇒ Boolean
Can the bucket be used as a log target?.
-
#logging ⇒ Object
Get logging status for bucket.
-
#object(key, options = {}) ⇒ Object
options
are passed to bucket.get; in addition, you can use: *:lazy => true
: this will prevent S33r from loading the content of the object from S3, instead just getting the object’s metadata from the bucket listing. -
#request_defaults ⇒ Object
Defaults for every request.
Methods inherited from Client
#bucket_exists?, #bucket_names, #buckets, #change_log_target_status, #create_bucket, #delete_bucket, #get_acl, #get_bucket, init, #list_bucket, #listing, #logs_off, #logs_to, #make_private, #make_public, #public?, #put, #put_file, #set_acl, #set_options, #settings, #url
Constructor Details
#initialize(bucket_name, options = {}) {|_self| ... } ⇒ Bucket
options
:
-
:check => true
: if setting a :bucket option, the default behaviour is not to check whether the bucket actually exists on S3. If you pass this option, S33r will only set the bucket if it is on S3 and accessible; if it isn’t, an error is raised (NoSuchBucket). -
:create => true
: if the bucket doesn’t exist, try to create it. S33r will check before trying to create the bucket and will just return the bucket if it does.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/s33r/bucket.rb', line 15 def initialize(bucket_name, ={}) bucket_name_valid?(bucket_name) super() if [:create] [:bucket] = bucket_name raise last_response.s3_error unless do_put(nil, ).ok? end if [:check] raise InvalidBucket, "Bucket #{name} does not exist" unless bucket_exists?(bucket_name) end @name = bucket_name yield self if block_given? end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/s33r/bucket.rb', line 5 def name @name end |
Instance Method Details
#[](key, load_object = true) ⇒ Object
Get an object from S3.
By default, this will load the content of the object. If you don’t want this, pass a :lazy option:
bucket['key', :lazy]
69 70 71 72 73 |
# File 'lib/s33r/bucket.rb', line 69 def [](key, load_object=true) = {} [:lazy] = true if :lazy == load_object object(key, ) end |
#delete(key, options = {}) ⇒ Object
Delete a key from inside the bucket.
50 51 52 53 |
# File 'lib/s33r/bucket.rb', line 50 def delete(key, ={}) [:key] = key do_delete().ok? end |
#destroy(options = {}) ⇒ Object
Destroy this bucket.
Pass :force => true
to delete the content of the bucket if it exists.
45 46 47 |
# File 'lib/s33r/bucket.rb', line 45 def destroy(={}) delete_bucket(name, ) end |
#exists? ⇒ Boolean
37 38 39 |
# File 'lib/s33r/bucket.rb', line 37 def exists? bucket_exists?(name) end |
#keys(options = {}) ⇒ Object
List of keys in the bucket.
options
are passed through to Client.listing. – TODO: tests
59 60 61 |
# File 'lib/s33r/bucket.rb', line 59 def keys(={}) listing().keys.sort end |
#log_receiver(state = :on) ⇒ Object
Change whether the bucket can be used to receive logs.
:on to make it a capable of receiving logs, :off to disable it as a log target.
97 98 99 |
# File 'lib/s33r/bucket.rb', line 97 def log_receiver(state=:on) change_log_target_status(name, state) end |
#log_receiver? ⇒ Boolean
Can the bucket be used as a log target?
89 90 91 |
# File 'lib/s33r/bucket.rb', line 89 def log_receiver? acl.log_targetable? end |
#logging ⇒ Object
Get logging status for bucket
102 103 104 |
# File 'lib/s33r/bucket.rb', line 102 def logging super(:bucket => name) end |
#object(key, options = {}) ⇒ Object
options
are passed to bucket.get; in addition, you can use:
-
:lazy => true
: this will prevent S33r from loading the content of the object from S3, instead just getting the object’s metadata from the bucket listing.
79 80 81 82 83 84 85 86 |
# File 'lib/s33r/bucket.rb', line 79 def object(key, ={}) obj = listing[key] if obj obj.bucket = self obj.fetch unless [:lazy] end obj end |
#request_defaults ⇒ Object
Defaults for every request.
33 34 35 |
# File 'lib/s33r/bucket.rb', line 33 def request_defaults super.merge(:bucket => name) end |