class AWS::S3::ObjectVersionCollection

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']

To see all the version id for a particular object, access the any particular version, and see the latest version:

object.versions.each do |version| puts version.version_id end
#=> T2TwAiZ3SmNr7tOfe0QBa4RZnSb3GSLq
#=> kAEHC_ysT65bT4P3zyYOP1ELA6ajar_6
#=> itHPX6m8na_sog0cAtkgP3QITEE8v5ij

object.versions['itHPX6m8na_sog0cAtkgP3QITEE8v5ij']
#=> <AWS::S3::ObjectVersion:<<bucket>>:myobj:itHPX6m8na_sog0cAtkgP3QITEE8v5ij>

object.versions.latest
#=> <AWS::S3::ObjectVersion:<<bucket>>:myobj:T2TwAiZ3SmNr7tOfe0QBa4RZnSb3GSLq>

If you know the id of a particular version you can get that object.

bucket.objets['myobj'].version[version_id].delete

Attributes

object[R]

@return [S3Object] The object this collection belongs to.

Public Class Methods

new(object, options = {}) click to toggle source

@param [S3Object] object

# File lib/aws/s3/object_version_collection.rb, line 55
def initialize object, options = {}
  @object = object
  super(options)
end

Public Instance Methods

[](version_id) click to toggle source

Returns an object that represents a single version of the {object}. @param [String] version_id @return [ObjectVersion]

# File lib/aws/s3/object_version_collection.rb, line 63
def [] version_id
  ObjectVersion.new(object, version_id)
end
each() { |version| ... } click to toggle source

Yields once for each version of the {object}.

@yield [object_version] @yieldparam [ObectVersion] object_version @return [nil]

# File lib/aws/s3/object_version_collection.rb, line 78
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() click to toggle source

@note Generally you will just want to grab the object key its key. @return [ObjectVersion] Returns the latest version of this object.

# File lib/aws/s3/object_version_collection.rb, line 69
def latest
  self.find{|version| true }
end