Class: AWS::S3::ObjectMetadata

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

Overview

Returns an object that represents the metadata for an S3 object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, options = {}) ⇒ ObjectMetadata

Returns a new instance of ObjectMetadata.

Parameters:

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

Options Hash (options):

  • :version_id (String)

    A specific version of the object to get metadata for



28
29
30
31
32
# File 'lib/aws/s3/object_metadata.rb', line 28

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ String?

Proxies the method to #[].

Returns:

  • (String, nil)

    Returns the metadata for the given name.



50
51
52
# File 'lib/aws/s3/object_metadata.rb', line 50

def method_missing name
  self[name]
end

Instance Attribute Details

#objectS3Object (readonly)

Returns:



35
36
37
# File 'lib/aws/s3/object_metadata.rb', line 35

def object
  @object
end

Instance Method Details

#[](name) ⇒ String?

Returns the value for the given name stored in the S3Objects metadata:

bucket.objects['myobject'].['purpose']
# returns nil if the given metadata key has not been set

Returns:

  • (String, nil)

    Returns the metadata for the given name.



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

def [] name
  to_h[name.to_s]
end

#to_hHash

Returns the user-generated metadata stored with this S3 Object.

Returns:

  • (Hash)

    Returns the user-generated metadata stored with this S3 Object.



56
57
58
59
60
61
62
# File 'lib/aws/s3/object_metadata.rb', line 56

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