Class: AWS::S3::ObjectMetadata
- Inherits:
-
Object
- Object
- AWS::S3::ObjectMetadata
- Includes:
- Core::Model
- Defined in:
- lib/aws/s3/object_metadata.rb
Overview
Returns an object that represents the metadata for an S3 object.
Instance Attribute Summary collapse
- #object ⇒ S3Object readonly
Attributes included from Core::Model
Instance Method Summary collapse
-
#[](name) ⇒ String?
Returns the value for the given name stored in the S3Object’s metadata:.
-
#[]=(name, value) ⇒ String?
Changes the value of the given name stored in the S3Object’s metadata:.
-
#initialize(object, options = {}) ⇒ ObjectMetadata
constructor
A new instance of ObjectMetadata.
-
#method_missing(name, *args, &blk) ⇒ String?
Proxies the method to #[].
-
#to_h ⇒ Hash
Returns the user-generated metadata stored with this S3 Object.
Methods included from Core::Model
#client, #config_prefix, #inspect
Constructor Details
#initialize(object, options = {}) ⇒ ObjectMetadata
Returns a new instance of ObjectMetadata.
26 27 28 29 30 |
# File 'lib/aws/s3/object_metadata.rb', line 26 def initialize object, = {} @object = object @version_id = [:version_id] super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &blk) ⇒ String?
Proxies the method to #[].
78 79 80 81 |
# File 'lib/aws/s3/object_metadata.rb', line 78 def method_missing name, *args, &blk return super if !args.empty? || blk self[name] end |
Instance Attribute Details
#object ⇒ S3Object (readonly)
33 34 35 |
# File 'lib/aws/s3/object_metadata.rb', line 33 def object @object end |
Instance Method Details
#[](name) ⇒ String?
Returns the value for the given name stored in the S3Object’s metadata:
bucket.objects['myobject'].['purpose']
# returns nil if the given metadata key has not been set
45 46 47 |
# File 'lib/aws/s3/object_metadata.rb', line 45 def [] name to_h[name.to_s] end |
#[]=(name, value) ⇒ String?
The name and value of each metadata field must conform to US-ASCII.
Changes the value of the given name stored in the S3Object’s metadata:
object = bucket.object['myobject']
object.['purpose'] = 'research'
object.['purpose'] # => 'research'
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/aws/s3/object_metadata.rb', line 65 def []= name, value raise "cannot change the metadata of an object version; "+ "use S3Object#write to create a new version with different metadata" if @version_id = to_h.dup [name.to_s] = value object.copy_from(object.key, :metadata => ) value end |
#to_h ⇒ Hash
Returns the user-generated metadata stored with this S3 Object.
85 86 87 88 89 90 91 |
# File 'lib/aws/s3/object_metadata.rb', line 85 def to_h = {} [:bucket_name] = object.bucket.name [:key] = object.key [:version_id] = @version_id if @version_id client.head_object(). end |