Class: Awsum::S3::Object
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#last_modified ⇒ Object
readonly
Returns the value of attribute last_modified.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#storage_class ⇒ Object
readonly
Returns the value of attribute storage_class.
Instance Method Summary collapse
-
#copy(new_key, headers = nil, meta_headers = nil) ⇒ Object
Make a copy of this Object with a new key.
-
#copy_to(new_bucket, new_key = nil, headers = nil, meta_headers = nil) ⇒ Object
Copy this Object to another Bucket.
-
#data(&block) ⇒ Object
Retrieve the data stored for this Object.
-
#delete ⇒ Object
Delete this Key.
-
#headers ⇒ Object
Get the headers for this Object.
-
#initialize(s3, bucket, key, last_modified, etag, size, owner, storage_class) ⇒ Object
constructor
A new instance of Object.
-
#move_to(new_bucket, new_key = nil, headers = nil, meta_headers = nil) ⇒ Object
Move this Object to another Bucket.
-
#rename(new_key, headers = nil, meta_headers = nil) ⇒ Object
(also: #move)
Rename or move this Object to a new key.
Constructor Details
#initialize(s3, bucket, key, last_modified, etag, size, owner, storage_class) ⇒ Object
Returns a new instance of Object.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/awsum/s3/object.rb', line 6 def initialize(s3, bucket, key, last_modified, etag, size, owner, storage_class) @s3 = s3 @bucket = bucket @key = key @last_modified = last_modified @etag = etag @size = size @owner = owner @storage_class = storage_class end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def bucket @bucket end |
#etag ⇒ Object (readonly)
Returns the value of attribute etag.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def etag @etag end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def key @key end |
#last_modified ⇒ Object (readonly)
Returns the value of attribute last_modified.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def last_modified @last_modified end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def owner @owner end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def size @size end |
#storage_class ⇒ Object (readonly)
Returns the value of attribute storage_class.
4 5 6 |
# File 'lib/awsum/s3/object.rb', line 4 def storage_class @storage_class end |
Instance Method Details
#copy(new_key, headers = nil, meta_headers = nil) ⇒ Object
Make a copy of this Object with a new key
46 47 48 |
# File 'lib/awsum/s3/object.rb', line 46 def copy(new_key, headers = nil, = nil) @s3.copy_object(@bucket, @key, nil, new_key, headers, ) end |
#copy_to(new_bucket, new_key = nil, headers = nil, meta_headers = nil) ⇒ Object
Copy this Object to another Bucket
59 60 61 |
# File 'lib/awsum/s3/object.rb', line 59 def copy_to(new_bucket, new_key = nil, headers = nil, = nil) @s3.copy_object(@bucket, @key, new_bucket, new_key, headers, ) end |
#data(&block) ⇒ Object
Retrieve the data stored for this Object
You can get the data as a single call or add a block to retrieve the data in chunks
Examples
content = object.data
or
object.data do |chunk|
# handle chunk
puts chunk
end
36 37 38 |
# File 'lib/awsum/s3/object.rb', line 36 def data(&block) @s3.object_data @bucket, @key, &block end |
#delete ⇒ Object
Delete this Key
41 42 43 |
# File 'lib/awsum/s3/object.rb', line 41 def delete @s3.delete_object(@bucket, @key) end |
#headers ⇒ Object
Get the headers for this Object
All header methods map directly to the Net::HTTPHeader module
20 21 22 |
# File 'lib/awsum/s3/object.rb', line 20 def headers @headers ||= @s3.object_headers(@bucket, @key) end |
#move_to(new_bucket, new_key = nil, headers = nil, meta_headers = nil) ⇒ Object
Move this Object to another Bucket
64 65 66 67 |
# File 'lib/awsum/s3/object.rb', line 64 def move_to(new_bucket, new_key = nil, headers = nil, = nil) copied = @s3.copy_object(@bucket, @key, new_bucket, new_key, headers, ) @s3.delete_object(@bucket, @key) if copied end |
#rename(new_key, headers = nil, meta_headers = nil) ⇒ Object Also known as: move
Rename or move this Object to a new key
51 52 53 54 |
# File 'lib/awsum/s3/object.rb', line 51 def rename(new_key, headers = nil, = nil) copied = @s3.copy_object(@bucket, @key, nil, new_key, headers, ) @s3.delete_object(@bucket, @key) if copied end |