Class: Nova::Common::Metadata::Options

Inherits:
BasicObject
Defined in:
lib/nova/common/metadata/options.rb

Overview

Note:

This stores everything in a hash, and all keys within hash are Strings, no matter what.

Handles options that are passed to the module.

API:

  • public

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Options

Initialize the options class.

Parameters:

  • the data to represent with this class.

API:

  • public



15
16
17
18
# File 'lib/nova/common/metadata/options.rb', line 15

def initialize(data)
  @_data = data
  _clean_data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object

Forwards all methods to the hash.

Parameters:

  • the method to forward.

  • the arguments for the method.

Returns:

API:

  • public



48
49
50
# File 'lib/nova/common/metadata/options.rb', line 48

def method_missing(method, *arguments, &block)
  @_data.public_send(method, *arguments, &block)
end

Instance Method Details

#[](key) ⇒ Object

Accessor for this class. Returns the default value if the key does not exist.

Parameters:

  • the key to look up.

Returns:

  • the value.

API:

  • public



25
26
27
# File 'lib/nova/common/metadata/options.rb', line 25

def [](key)
  fetch(key) { default(key.to_s) }
end

#fetch(key, *args) {|key| ... } ⇒ Object

Fetches the given key. If it doesn’t exist, uses the given default value or calls the block.

Parameters:

  • the key to look up.

  • the default object to return, if the key doesn’t exist in the table.

Yield Parameters:

  • key (String)

    the key that was looked up.

Yield Returns:

  • (Object)

    the value to use.

Returns:

  • the value of the key.

API:

  • public



38
39
40
# File 'lib/nova/common/metadata/options.rb', line 38

def fetch(key, *args, &block)
  @_data.fetch(key.to_s, *args, &block)
end