Class: Fog::Storage::Rackspace::Metadata
- Inherits:
-
Object
- Object
- Fog::Storage::Rackspace::Metadata
- Defined in:
- lib/fog/rackspace/models/storage/metadata.rb
Constant Summary collapse
- OBJECT_META_PREFIX =
"X-Object-Meta-"
- OBJECT_REMOVE_META_PREFIX =
"X-Remove-Object-Meta-"
- CONTAINER_META_PREFIX =
"X-Container-Meta-"
- CONTAINER_REMOVE_META_PREFIX =
"X-Remove-Container-Meta-"
- DUMMY_VALUE =
Cloud Files will ignore headers without a value
1
- CONTAINER_KEY_REGEX =
/^#{CONTAINER_META_PREFIX}(.*)/
- OBJECT_KEY_REGEX =
/^#{OBJECT_META_PREFIX}(.*)/
Instance Attribute Summary collapse
-
#data ⇒ Hash
Underlying data store for metadata class.
-
#parent ⇒ Fog::Storage::Rackspace::Directory, Fog::Storage::Rackspace::File
The parent object of the metadata.
Class Method Summary collapse
-
.from_headers(parent, headers) ⇒ Object
Creates metadata object from Cloud File Headers.
Instance Method Summary collapse
-
#delete(key) ⇒ Object
Delete key value pair from metadata.
-
#initialize(parent, hash = {}) ⇒ Metadata
constructor
Initialize.
-
#method_missing(method, *args, &block) ⇒ Object
Invoked by Ruby when obj is sent a message it cannot handle.
-
#respond_to?(method_sym, include_private = false) ⇒ Boolean
Returns true if method is implemented by Metadata class.
-
#to_headers ⇒ Hash
Returns metadata in a format expected by Cloud Files.
Constructor Details
#initialize(parent, hash = {}) ⇒ Metadata
Initialize
35 36 37 38 39 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 35 def initialize(parent, hash={}) @data = hash || {} @deleted_hash = {} @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Invoked by Ruby when obj is sent a message it cannot handle.
85 86 87 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 85 def method_missing(method, *args, &block) data.send(method, *args, &block) end |
Instance Attribute Details
#data ⇒ Hash
Returns underlying data store for metadata class.
26 27 28 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 26 def data @data end |
#parent ⇒ Fog::Storage::Rackspace::Directory, Fog::Storage::Rackspace::File
Returns the parent object of the metadata.
30 31 32 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 30 def parent @parent end |
Class Method Details
.from_headers(parent, headers) ⇒ Object
Creates metadata object from Cloud File Headers
67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 67 def self.from_headers(parent, headers) = Metadata.new(parent) headers.each_pair do |k, v| key = .send(:to_key, k) next unless key .data[key] = v end end |
Instance Method Details
#delete(key) ⇒ Object
Metadata must be deleted using this method in order to properly remove it from Cloud Files
Delete key value pair from metadata
46 47 48 49 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 46 def delete(key) data.delete(key) @deleted_hash[key] = nil end |
#respond_to?(method_sym, include_private = false) ⇒ Boolean
Returns true if method is implemented by Metadata class
80 81 82 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 80 def respond_to?(method_sym, include_private = false) super(method_sym, include_private) || data.respond_to?(method_sym, include_private) end |
#to_headers ⇒ Hash
Returns metadata in a format expected by Cloud Files
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 53 def to_headers headers = {} h = data.merge(@deleted_hash) h.each_pair do |k,v| key = to_header_key(k,v) headers[key] = v || DUMMY_VALUE end headers end |