Class: AWS::S3::ObjectVersionCollection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ ObjectVersionCollection

Returns a new instance of ObjectVersionCollection.

Parameters:



44
45
46
47
# File 'lib/aws/s3/object_version_collection.rb', line 44

def initialize object, options = {}
  @object = object
  super(options)
end

Instance Attribute Details

#objectS3Object (readonly)

Returns The object this collection belongs to.

Returns:

  • (S3Object)

    The object this collection belongs to.



41
42
43
# File 'lib/aws/s3/object_version_collection.rb', line 41

def object
  @object
end

Instance Method Details

#[](version_id) ⇒ ObjectVersion

Returns an object that represents a single version of the #object.

Parameters:

  • version_id (String)

Returns:



52
53
54
# File 'lib/aws/s3/object_version_collection.rb', line 52

def [] version_id
  ObjectVersion.new(object, version_id)
end

#each {|object_version| ... } ⇒ nil

Yields once for each version of the #object.

Yields:

  • (object_version)

Yield Parameters:

  • object_version (ObectVersion)

Returns:

  • (nil)


67
68
69
70
71
72
73
74
# File 'lib/aws/s3/object_version_collection.rb', line 67

def each &block
  object.bucket.versions.with_prefix(object.key).each do |version|
    if version.key == object.key
      yield(version)
    end
  end
  nil
end

#latestObjectVersion

Note:

Generally you will just want to grab the object key its key.

Returns the latest version of this object.

Returns:



58
59
60
# File 'lib/aws/s3/object_version_collection.rb', line 58

def latest
  self.find{|version| true }
end