Class: AWS::S3::ObjectVersionCollection
- Inherits:
-
Object
- Object
- AWS::S3::ObjectVersionCollection
- Includes:
- Enumerable
- Defined in:
- lib/aws/s3/object_version_collection.rb
Overview
For S3 buckets with versioning enabled, objects will store versions each time you write to them.
object = bucket.objects['myobj']
object.write('1')
object.write('2')
object.write('3')
object.versions.collect(&:read)
#=> ['1', '2', '3']
If you know the id of a particular version you can get that object.
bucket.objets['myobj'].version[version_id].delete
Instance Attribute Summary collapse
-
#object ⇒ S3Object
readonly
The object this collection belongs to.
Instance Method Summary collapse
-
#[](version_id) ⇒ ObjectVersion
Returns an object that represents a single version of the #object.
-
#each {|object_version| ... } ⇒ nil
Yields once for each version of the #object.
-
#initialize(object, options = {}) ⇒ ObjectVersionCollection
constructor
A new instance of ObjectVersionCollection.
-
#latest ⇒ ObjectVersion
Returns the latest version of this object.
Constructor Details
#initialize(object, options = {}) ⇒ ObjectVersionCollection
Returns a new instance of ObjectVersionCollection.
41 42 43 44 |
# File 'lib/aws/s3/object_version_collection.rb', line 41 def initialize object, = {} @object = object super() end |
Instance Attribute Details
#object ⇒ S3Object (readonly)
Returns The object this collection belongs to.
38 39 40 |
# File 'lib/aws/s3/object_version_collection.rb', line 38 def object @object end |
Instance Method Details
#[](version_id) ⇒ ObjectVersion
Returns an object that represents a single version of the #object.
49 50 51 |
# File 'lib/aws/s3/object_version_collection.rb', line 49 def [] version_id ObjectVersion.new(object, version_id) end |
#each {|object_version| ... } ⇒ nil
Yields once for each version of the #object.
64 65 66 67 68 69 70 71 |
# File 'lib/aws/s3/object_version_collection.rb', line 64 def each &block object.bucket.versions.with_prefix(object.key).each do |version| if version.key == object.key yield(version) end end nil end |
#latest ⇒ ObjectVersion
Note:
Generally you will just want to grab the object key its key.
Returns the latest version of this object.
55 56 57 |
# File 'lib/aws/s3/object_version_collection.rb', line 55 def latest self.find{|version| true } end |