Class: Awsum::S3::Object

Inherits:
Object show all
Defined in:
lib/awsum/s3/object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bucketObject (readonly)

Returns the value of attribute bucket.



4
5
6
# File 'lib/awsum/s3/object.rb', line 4

def bucket
  @bucket
end

#etagObject (readonly)

Returns the value of attribute etag.



4
5
6
# File 'lib/awsum/s3/object.rb', line 4

def etag
  @etag
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/awsum/s3/object.rb', line 4

def key
  @key
end

#last_modifiedObject (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

#ownerObject (readonly)

Returns the value of attribute owner.



4
5
6
# File 'lib/awsum/s3/object.rb', line 4

def owner
  @owner
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/awsum/s3/object.rb', line 4

def size
  @size
end

#storage_classObject (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, meta_headers = nil)
  @s3.copy_object(@bucket, @key, nil, new_key, headers, meta_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, meta_headers = nil)
  @s3.copy_object(@bucket, @key, new_bucket, new_key, headers, meta_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

#deleteObject

Delete this Key



41
42
43
# File 'lib/awsum/s3/object.rb', line 41

def delete
  @s3.delete_object(@bucket, @key)
end

#headersObject

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, meta_headers = nil)
  copied = @s3.copy_object(@bucket, @key, new_bucket, new_key, headers, meta_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, meta_headers = nil)
  copied = @s3.copy_object(@bucket, @key, nil, new_key, headers, meta_headers)
  @s3.delete_object(@bucket, @key) if copied
end