Class: AWS::S3::ObjectVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/s3/object_version.rb

Overview

Represents a single version of an S3Object.

When you enable versioning on a S3 bucket, writing to an object will create an object version instead of replacing the existing object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, version_id, options = {}) ⇒ ObjectVersion

Returns a new instance of ObjectVersion.

Parameters:

  • object (S3Object)

    The object this is a version of.

  • version_id (String)

    The unique id for this version.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :delete_marker (Boolean)

    Is this version a delete marker?



34
35
36
37
38
39
# File 'lib/aws/s3/object_version.rb', line 34

def initialize(object, version_id, options = {})
  @object = object
  @version_id = version_id
  @delete_marker = options[:delete_marker]
  super
end

Instance Attribute Details

#objectS3Object (readonly)

Returns the object this is a version of.

Returns:

  • (S3Object)

    the object this is a version of.



42
43
44
# File 'lib/aws/s3/object_version.rb', line 42

def object
  @object
end

#version_idString (readonly)

Returns The unique version identifier.

Returns:

  • (String)

    The unique version identifier.



49
50
51
# File 'lib/aws/s3/object_version.rb', line 49

def version_id
  @version_id
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true if the other object version has the same s3 object key and version id.

Returns:

  • (Boolean)

    Returns true if the other object version has the same s3 object key and version id.



126
127
128
129
130
# File 'lib/aws/s3/object_version.rb', line 126

def ==(other)
  other.kind_of?(ObjectVersion) and
    other.object == object and
    other.version_id == version_id
end

#bucketObject



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

def bucket
  object.bucket
end

#content_lengthInteger

Returns Size of the object in bytes.

Returns:

  • (Integer)

    Size of the object in bytes.



69
70
71
# File 'lib/aws/s3/object_version.rb', line 69

def content_length
  head.content_length
end

#content_typeString

Note:

S3 does not compute content-type. It reports the content-type as was reported during the file upload.

Returns the content type as reported by S3, defaults to an empty string when not provided during upload.

Returns:

  • (String)

    Returns the content type as reported by S3, defaults to an empty string when not provided during upload.

See Also:



76
77
78
# File 'lib/aws/s3/object_version.rb', line 76

def content_type
  head.content_type
end

#deletenil

Deletes this object version from S3.

Returns:

  • (nil)


96
97
98
# File 'lib/aws/s3/object_version.rb', line 96

def delete
  object.delete(:version_id => @version_id)
end

#delete_marker?Boolean

If you delete an object in a versioned bucket, a delete marker is created.

Returns:

  • (Boolean)

    Returns true if this version is a delete marker.



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/aws/s3/object_version.rb', line 110

def delete_marker?
  if @delete_marker.nil?
    begin
      # S3 responds with a 405 (method not allowed) when you try
      # to HEAD an s3 object version that is a delete marker
      ['foo'] 
      @delete_marker = false
    rescue Errors::MethodNotAllowed => error
      @delete_marker = true
    end
  end
  @delete_marker
end

#etagString

Returns the object’s ETag

Returns:

  • (String)

    Returns the object’s ETag

See Also:



64
65
66
# File 'lib/aws/s3/object_version.rb', line 64

def etag
  head.etag
end

#headObject

Returns A head object response with metatadata, content_length, content_type and etag.

Returns:

  • A head object response with metatadata, content_length, content_type and etag.

See Also:



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

def head
  object.head(:version_id => @version_id)
end

#keyString

Returns The objects unique key.

Returns:

  • (String)

    The objects unique key



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

def key
  object.key
end

#latest?Boolean

Returns this if this is the latest version of the object, false if the object has been written to since this version was created.

Returns:

  • (Boolean)

    Returns this if this is the latest version of the object, false if the object has been written to since this version was created.



103
104
105
# File 'lib/aws/s3/object_version.rb', line 103

def latest?
  object.versions.latest.version_id == self.version_id
end

#metadataObjectMetadata

Returns an instance of ObjectMetadata representing the metadata for this object.

Returns:

  • (ObjectMetadata)

    Returns an instance of ObjectMetadata representing the metadata for this object.

See Also:



82
83
84
# File 'lib/aws/s3/object_version.rb', line 82

def 
  object.(:version_id => @version_id)
end

#read(options = {}, &block) ⇒ Object

Reads the data from this object version.

See Also:



90
91
92
# File 'lib/aws/s3/object_version.rb', line 90

def read options = {}, &block
  object.read(options.merge(:version_id => @version_id), &block)
end