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

Parameters:



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

#dataHash

Returns underlying data store for metadata class.

Returns:

  • (Hash)

    underlying data store for metadata class



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

def data
  @data
end

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

Returns the parent object of the metadata.

Returns:



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

Parameters:



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

Note:

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

Delete key value pair from metadata

Parameters:

  • key (String)

    to be deleted

Returns:

  • (Object)

    returns value for key



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

Parameters:

  • method_sym (Symbol)
  • include_private (Boolean) (defaults to: false)

Returns:

  • (Boolean)


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_headersHash

Returns metadata in a format expected by Cloud Files

Returns:

  • (Hash)

    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