Class: AWS::S3::ObjectVersion
- Inherits:
-
Object
- Object
- AWS::S3::ObjectVersion
- Includes:
- Core::Model
- 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
-
#object ⇒ S3Object
readonly
The object this is a version of.
-
#version_id ⇒ String
readonly
The unique version identifier.
Attributes included from Core::Model
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Returns true if the other object version has the same s3 object key and version id.
- #bucket ⇒ Object
-
#content_length ⇒ Integer
Size of the object in bytes.
-
#content_type ⇒ String
Returns the content type as reported by S3, defaults to an empty string when not provided during upload.
-
#delete ⇒ nil
Deletes this object version from S3.
-
#delete_marker? ⇒ Boolean
If you delete an object in a versioned bucket, a delete marker is created.
-
#etag ⇒ String
Returns the object’s ETag.
-
#head ⇒ Object
A head object response with metatadata, content_length, content_type, etag and server_side_encryption.
-
#initialize(object, version_id, options = {}) ⇒ ObjectVersion
constructor
A new instance of ObjectVersion.
- #inspect ⇒ Object
-
#key ⇒ String
The objects unique key.
-
#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.
-
#metadata ⇒ ObjectMetadata
Returns an instance of ObjectMetadata representing the metadata for this object.
-
#read(options = {}, &block) ⇒ Object
Reads the data from this object version.
-
#url_for(method, options = {}) ⇒ URI::HTTP, URI::HTTPS
Generates a presigned URL for an operation on this object.
Methods included from Core::Model
Constructor Details
#initialize(object, version_id, options = {}) ⇒ ObjectVersion
Returns a new instance of ObjectVersion.
31 32 33 34 35 36 |
# File 'lib/aws/s3/object_version.rb', line 31 def initialize(object, version_id, = {}) @object = object @version_id = version_id @delete_marker = [:delete_marker] super end |
Instance Attribute Details
#object ⇒ S3Object (readonly)
Returns the object this is a version of.
39 40 41 |
# File 'lib/aws/s3/object_version.rb', line 39 def object @object end |
#version_id ⇒ String (readonly)
Returns The unique version identifier.
46 47 48 |
# File 'lib/aws/s3/object_version.rb', line 46 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.
128 129 130 131 132 |
# File 'lib/aws/s3/object_version.rb', line 128 def ==(other) other.kind_of?(ObjectVersion) and other.object == object and other.version_id == version_id end |
#bucket ⇒ Object
41 42 43 |
# File 'lib/aws/s3/object_version.rb', line 41 def bucket object.bucket end |
#content_length ⇒ Integer
Returns Size of the object in bytes.
71 72 73 |
# File 'lib/aws/s3/object_version.rb', line 71 def content_length head.content_length end |
#content_type ⇒ String
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.
78 79 80 |
# File 'lib/aws/s3/object_version.rb', line 78 def content_type head.content_type end |
#delete ⇒ nil
Deletes this object version from S3.
98 99 100 |
# File 'lib/aws/s3/object_version.rb', line 98 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.
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/aws/s3/object_version.rb', line 112 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 |
#etag ⇒ String
Returns the object’s ETag
66 67 68 |
# File 'lib/aws/s3/object_version.rb', line 66 def etag head.etag end |
#head ⇒ Object
Returns A head object response with metatadata, content_length, content_type, etag and server_side_encryption.
60 61 62 |
# File 'lib/aws/s3/object_version.rb', line 60 def head object.head(:version_id => @version_id) end |
#inspect ⇒ Object
137 138 139 |
# File 'lib/aws/s3/object_version.rb', line 137 def inspect "<#{self.class}:#{object.bucket.name}:#{object.key}:#{version_id}>" end |
#key ⇒ String
Returns The objects unique key.
49 50 51 |
# File 'lib/aws/s3/object_version.rb', line 49 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.
105 106 107 |
# File 'lib/aws/s3/object_version.rb', line 105 def latest? object.versions.latest.version_id == self.version_id end |
#metadata ⇒ ObjectMetadata
Returns an instance of ObjectMetadata representing the metadata for this object.
84 85 86 |
# File 'lib/aws/s3/object_version.rb', line 84 def object.(:version_id => @version_id) end |
#read(options = {}, &block) ⇒ Object
Reads the data from this object version.
92 93 94 |
# File 'lib/aws/s3/object_version.rb', line 92 def read = {}, &block object.read(.merge(:version_id => @version_id), &block) end |
#url_for(method, options = {}) ⇒ URI::HTTP, URI::HTTPS
Generates a presigned URL for an operation on this object. This URL can be used by a regular HTTP client to perform the desired operation without credentials and without changing the permissions of the object.
54 55 56 |
# File 'lib/aws/s3/object_version.rb', line 54 def url_for method, = {} object.url_for(method, .merge(:version_id => version_id)) end |