Returns an object that represents the metadata for an S3 object.
@return [S3Object]
@param [S3Object] @param [Hash] options @option options [String] :version_id A specific version of the object
to get metadata for
# File lib/aws/s3/object_metadata.rb, line 26 def initialize(object, options = {}) @object = object @version_id = options[:version_id] super end
Returns the value for the given name stored in the S3Object’s metadata:
bucket.objects['myobject'].metadata['purpose'] # returns nil if the given metadata key has not been set
@param [String,Symbol] name The name of the metadata field to
get.
@return [String,nil] Returns the metadata for the given name.
# File lib/aws/s3/object_metadata.rb, line 45 def [] name to_h[name.to_s] end
Changes the value of the given name stored in the S3Object’s metadata:
object = bucket.object['myobject'] object.metadata['purpose'] = 'research' object.metadata['purpose'] # => 'research'
@note The name and value of each metadata field must conform
to US-ASCII.
@param [String,Symbol] name The name of the metadata field to
set.
@param [String] value The new value of the metadata field.
@return [String,nil] Returns the value that was set.
# 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 metadata = to_h.dup metadata[name.to_s] = value object.copy_from(object.key, :metadata => metadata) value end
Proxies the method to {#[]}. @return (see #[])
# File lib/aws/s3/object_metadata.rb, line 78 def method_missing name, *args, &blk return super if !args.empty? || blk self[name] end
@return [Hash] Returns the user-generated metadata stored with
this S3 Object.
# File lib/aws/s3/object_metadata.rb, line 85 def to_h options = {} options[:bucket_name] = object.bucket.name options[:key] = object.key options[:version_id] = @version_id if @version_id client.head_object(options).meta end