Class: Aws::S3::ObjectSummary
- Inherits:
-
Object
- Object
- Aws::S3::ObjectSummary
- Extended by:
- Deprecations
- Defined in:
- sig/object_summary.rbs,
lib/aws-sdk-s3/object_summary.rb,
lib/aws-sdk-s3/customizations/object_summary.rb,
sig/customizations/object_summary.rbs
Overview
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
- #bucket_name ⇒ String
- #checksum_algorithm ⇒ ::Array[("CRC32" | "CRC32C" | "SHA1" | "SHA256" | "CRC64NVME" | "SHA512" | "MD5" | "XXHASH64" | "XXHASH3" | "XXHASH128")]
- #checksum_type ⇒ "COMPOSITE", "FULL_OBJECT"
- #etag ⇒ ::String
- #key ⇒ String
- #last_modified ⇒ ::Time
- #owner ⇒ Types::Owner
- #restore_status ⇒ Types::RestoreStatus
- #size ⇒ ::Integer (also: #content_length)
- #storage_class ⇒ "STANDARD", ...
Actions collapse
- #copy_from(source, options = {}) ⇒ Object
- #delete(options = {}) ⇒ Object
- #get(options = {}, &block) ⇒ Object
- #initiate_multipart_upload(options = {}) ⇒ Object
- #put(options = {}) ⇒ Object
- #restore_object(options = {}) ⇒ Object
Associations collapse
- #acl ⇒ ObjectAcl
- #bucket ⇒ Bucket
- #identifiers ⇒ Object deprecated private Deprecated.
- #multipart_upload(id) ⇒ MultipartUpload
- #object ⇒ Object
- #version(id) ⇒ ObjectVersion
Instance Method Summary collapse
- #client ⇒ Client
- #copy_to(target, options = {}) ⇒ void
- #data ⇒ Types::Object
- #data_loaded? ⇒ Boolean
- #download_file(destination, options = {}) ⇒ Boolean
- #exists?(options = {}) ⇒ Object
- #initialize(*args) ⇒ ObjectSummary constructor
- #load ⇒ Object (also: #reload) private
- #move_to(target, options = {}) ⇒ void
- #presigned_post(options = {}) ⇒ Object
- #presigned_url(http_method, params = {}) ⇒ String
- #public_url(options = {}) ⇒ String
- #upload_file(source, options = {}) ⇒ void
- #upload_stream(options = {}) {|write_stream| ... } ⇒ Boolean
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::S3::Client] #wait_until instead
- #wait_until_exists(options = {}, &block) ⇒ Object
- #wait_until_not_exists(options = {}, &block) ⇒ Object
Constructor Details
#initialize(bucket_name, key, options) ⇒ void #initialize(bucket_name:, key:, client:) ⇒ void #initialize(args) ⇒ void
24 25 26 27 28 29 30 31 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 24 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @bucket_name = extract_bucket_name(args, ) @key = extract_key(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#acl ⇒ ObjectAcl
3002 3003 3004 3005 3006 3007 3008 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 3002 def acl ObjectAcl.new( bucket_name: @bucket_name, object_key: @key, client: @client ) end |
#bucket ⇒ Bucket
3011 3012 3013 3014 3015 3016 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 3011 def bucket Bucket.new( name: @bucket_name, client: @client ) end |
#bucket_name ⇒ String
36 37 38 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 36 def bucket_name @bucket_name end |
#checksum_algorithm ⇒ ::Array[("CRC32" | "CRC32C" | "SHA1" | "SHA256" | "CRC64NVME" | "SHA512" | "MD5" | "XXHASH64" | "XXHASH3" | "XXHASH128")]
83 84 85 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 83 def checksum_algorithm data[:checksum_algorithm] end |
#checksum_type ⇒ "COMPOSITE", "FULL_OBJECT"
95 96 97 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 95 def checksum_type data[:checksum_type] end |
#client ⇒ Client
153 154 155 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 153 def client @client end |
#copy_from(source, options) ⇒ void #copy_from ⇒ void
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1158 def copy_from( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.copy_object() end resp.data end |
#copy_to(target, options = {}) ⇒ void
This method returns an undefined value.
https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/ObjectSummary.html#copy_to-instance_method
24 25 26 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 24 def copy_to(target, = {}) object.copy_to(target, ) end |
#data ⇒ Types::Object
168 169 170 171 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 168 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
176 177 178 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 176 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Object
1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1265 def delete( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.delete_object() end resp.data end |
#download_file(destination, options = {}) ⇒ Boolean
79 80 81 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 79 def download_file(destination, = {}) object.download_file(destination, ) end |
#etag ⇒ ::String
77 78 79 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 77 def etag data[:etag] end |
#exists?(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ Boolean #exists?(arg0) ⇒ Boolean
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 183 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#get(options = {}, &block) ⇒ Object
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 1521 def get( = {}, &block) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.get_object(, &block) end resp.data end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
3051 3052 3053 3054 3055 3056 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 3051 def identifiers { bucket_name: @bucket_name, key: @key } end |
#initiate_multipart_upload(options = {}) ⇒ Object
2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2129 def initiate_multipart_upload( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.create_multipart_upload() end MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: resp.data.upload_id, client: @client ) end |
#key ⇒ String
41 42 43 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 41 def key @key end |
#last_modified ⇒ ::Time
47 48 49 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 47 def last_modified data[:last_modified] end |
#load ⇒ Object Also known as: reload
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
159 160 161 162 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 159 def load msg = "#load is not implemented, data only available via enumeration" raise NotImplementedError, msg end |
#move_to(target, options = {}) ⇒ void
This method returns an undefined value.
https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/ObjectSummary.html#move_to-instance_method
32 33 34 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 32 def move_to(target, = {}) object.move_to(target, ) end |
#multipart_upload(id) ⇒ MultipartUpload
3020 3021 3022 3023 3024 3025 3026 3027 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 3020 def multipart_upload(id) MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#object ⇒ Object
3030 3031 3032 3033 3034 3035 3036 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 3030 def object Object.new( bucket_name: @bucket_name, key: @key, client: @client ) end |
#owner ⇒ Types::Owner
125 126 127 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 125 def owner data[:owner] end |
#presigned_post(options = {}) ⇒ Object
40 41 42 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 40 def presigned_post( = {}) object.presigned_post() end |
#presigned_url(http_method, params = {}) ⇒ String
48 49 50 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 48 def presigned_url(http_method, params = {}) object.presigned_url(http_method, params) end |
#public_url(options = {}) ⇒ String
56 57 58 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 56 def public_url( = {}) object.public_url() end |
#put(options = {}) ⇒ Object
2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2847 def put( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.put_object() end resp.data end |
#restore_object(options = {}) ⇒ Object
2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 2988 def restore_object( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do @client.restore_object() end resp.data end |
#restore_status ⇒ Types::RestoreStatus
146 147 148 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 146 def restore_status data[:restore_status] end |
#size ⇒ ::Integer Also known as: content_length
101 102 103 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 101 def size data[:size] end |
#storage_class ⇒ "STANDARD", ...
114 115 116 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 114 def storage_class data[:storage_class] end |
#upload_file(source, options = {}) ⇒ void
This method returns an undefined value.
64 65 66 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 64 def upload_file(source, = {}) object.upload_file(source, ) end |
#upload_stream(options = {}) {|write_stream| ... } ⇒ Boolean
71 72 73 |
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 71 def upload_stream( = {}, &block) object.upload_stream(, &block) end |
#version(id) ⇒ ObjectVersion
3040 3041 3042 3043 3044 3045 3046 3047 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 3040 def version(id) ObjectVersion.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::S3::Client] #wait_until instead
The waiting operation is performed on a copy. The original resource remains unchanged.
Waiter polls an API operation until a resource enters a desired state.
Basic Usage
Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.
# polls in a loop until condition is true
resource.wait_until() {|resource| condition}
Example
instance.wait_until(max_attempts:10, delay:5) do |instance|
instance.state.name == 'running'
end
Configuration
You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:
# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}
Callbacks
You can be notified before each polling attempt and before each
delay. If you throw :success or :failure from these callbacks,
it will terminate the waiter.
started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
throw :failure if Time.now - started_at > 3600
end
# disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}
Handling Errors
When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.
begin
resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
# resource did not enter the desired state in time
end
attempts attempt in seconds invoked before each attempt invoked before each wait
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 316 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do Aws::Waiters::Waiter.new().wait({}) end end |
#wait_until_exists(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ void #wait_until_exists(arg0) ⇒ void
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 200 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::ObjectExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(bucket: @bucket_name, key: @key)) end ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |
#wait_until_not_exists(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ void #wait_until_not_exists(arg0) ⇒ void
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/aws-sdk-s3/object_summary.rb', line 221 def wait_until_not_exists( = {}, &block) , params = () waiter = Waiters::ObjectNotExists.new() yield_waiter_and_warn(waiter, &block) if block_given? Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do waiter.wait(params.merge(bucket: @bucket_name, key: @key)) end ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |