Class RightAws::S3::Key
In: lib/s3/right_s3.rb
Parent: Object

Methods

add_meta_prefix   content_type   copy   create   data   decoded_meta_headers   delete   exists?   full_name   get   grantees   head   move   new   public_link   put   refresh   reload_meta   rename   save_meta   to_s  

Attributes

bucket  [R] 
data  [W] 
e_tag  [R] 
headers  [RW] 
last_modified  [R] 
meta_headers  [RW] 
name  [R] 
owner  [R] 
size  [R] 
storage_class  [R] 

Public Class methods

Create a new Key instance, but do not create the actual key. The name is a String. Returns a new Key instance.

 key = RightAws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 key.exists?                                                  #=> true | false
 key.put('Woohoo!')                                           #=> true
 key.exists?                                                  #=> true

Create a new Key instance, but do not create the actual key. In normal use this method should not be called directly. Use RightAws::S3::Key.create or bucket.key() instead.

Public Instance methods

Getter for the ‘content-type’ metadata

Create an object copy. Returns a destination RightAws::S3::Key instance.

 # Key instance as destination
 key1 = RightAws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 key2 = RightAws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<RightAws::S3::Key:0xb7b5e240 ... >
 key1.put('Olala!')   #=> true
 key1.copy(key2)      #=> #<RightAws::S3::Key:0xb7b5e240 ... >
 key1.exists?         #=> true
 key2.exists?         #=> true
 puts key2.data       #=> 'Olala!'

 # String as destination
 key = RightAws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 key.put('Olala!')                          #=> true
 new_key = key.copy('logs/today/888.log')   #=> #<RightAws::S3::Key:0xb7b5e240 ... >
 key.exists?                                #=> true
 new_key.exists?                            #=> true

Return Key data. Retrieve this data from Amazon if it is the first time call. TODO TRB 6/19/07 What does the above mean? Clarify.

Helper to get and URI-decode a header metadata. Metadata have to be HTTP encoded (rfc2616) as we use the Amazon S3 REST api see docs.amazonwebservices.com/AmazonS3/latest/index.html?UsingMetadata.html

Remove key from bucket. Returns true.

 key.delete #=> true

Check for existence of the key in the given bucket. Returns true or false.

 key = RightAws::S3::Key.create(bucket,'logs/today/1.log')
 key.exists?        #=> false
 key.put('Woohoo!') #=> true
 key.exists?        #=> true

Return the full S3 path to this key (bucket/key).

 key.full_name #=> 'my_awesome_bucket/cool_key'

Retrieve object data and attributes from Amazon. Returns a String.

Return a list of grantees.

Updates headers and meta-headers from S3. Returns true.

 key.meta_headers #=> {"family"=>"qwerty"}
 key.head         #=> true
 key.meta_headers #=> {"family"=>"qwerty", "name"=>"asdfg"}

Move an object to other location. Returns a destination RightAws::S3::Key instance.

 # Key instance as destination
 key1 = RightAws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 key2 = RightAws::S3::Key.create(bucket, 'logs/today/2.log') #=> #<RightAws::S3::Key:0xb7b5e240 ... >
 key1.put('Olala!')   #=> true
 key1.move(key2)      #=> #<RightAws::S3::Key:0xb7b5e240 ... >
 key1.exists?         #=> false
 key2.exists?         #=> true
 puts key2.data       #=> 'Olala!'

 # String as destination
 key = RightAws::S3::Key.create(bucket, 'logs/today/777.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 key.put('Olala!')                          #=> true
 new_key = key.move('logs/today/888.log')   #=> #<RightAws::S3::Key:0xb7b5e240 ... >
 key.exists?                                #=> false
 new_key.exists?                            #=> true

Return a public link to a key.

 key.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket/cool_key'

Store object data on S3. Parameter data is a String or S3Object instance. Returns true.

 key = RightAws::S3::Key.create(bucket, 'logs/today/1.log')
 key.data = 'Qwerty'
 key.put             #=> true
  ...
 key.put('Olala!')   #=> true

Retrieve key info from bucket and update attributes. Refresh meta-headers (by calling head method) if head is set. Returns true if the key exists in bucket and false otherwise.

 key = RightAws::S3::Key.create(bucket, 'logs/today/1.log')
 key.e_tag        #=> nil
 key.meta_headers #=> {}
 key.refresh      #=> true
 key.e_tag        #=> '12345678901234567890bf11094484b6'
 key.meta_headers #=> {"family"=>"qwerty", "name"=>"asdfg"}

Reload meta-headers only. Returns meta-headers hash.

 key.reload_meta   #=> {"family"=>"qwerty", "name"=>"asdfg"}

Rename an object. Returns new object name.

 key = RightAws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 key.rename('logs/today/2.log')   #=> 'logs/today/2.log'
 puts key.name                    #=> 'logs/today/2.log'
 key.exists?                      #=> true

Replace meta-headers by new hash at S3. Returns new meta-headers hash.

 key.reload_meta   #=> {"family"=>"qwerty", "name"=>"asdfg"}
 key.save_meta     #=> {"family"=>"oops", "race" => "troll"}
 key.reload_meta   #=> {"family"=>"oops", "race" => "troll"}

Return key name as a String.

 key = RightAws::S3::Key.create(bucket, 'logs/today/1.log') #=> #<RightAws::S3::Key:0xb7b1e240 ... >
 puts key                                                   #=> 'logs/today/1.log'

[Validate]