Class: Fog::Storage::Rackspace::Metadata

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, hash = {}) ⇒ Metadata

Initialize



30
31
32
33
34
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 30

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.



80
81
82
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 80

def method_missing(method, *args, &block)
  data.send(method, *args, &block)
end

Instance Attribute Details

#dataHash



21
22
23
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 21

def data
  @data
end

#parentFog::Storage::Rackspace::Directory, Fog::Storage::Rackspace::File



25
26
27
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 25

def parent
  @parent
end

Class Method Details

.from_headers(parent, headers) ⇒ Object

Creates metadata object from Cloud File Headers



62
63
64
65
66
67
68
69
70
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 62

def self.from_headers(parent, headers)
   = .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

Note:

Metadata must be deleted using this method in order to properly remove it from Cloud Files

Delete key value pair from metadata



41
42
43
44
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 41

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



75
76
77
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 75

def respond_to?(method_sym, include_private = false)
  super(method_sym, include_private) || data.respond_to?(method_sym, include_private)
end

#to_headersHash

Returns metadata in a format expected by Cloud Files



48
49
50
51
52
53
54
55
56
57
# File 'lib/fog/rackspace/models/storage/metadata.rb', line 48

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