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.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Accessor for this class.
-
#fetch(key, *args) {|key| ... } ⇒ Object
Fetches the given key.
-
#initialize(data) ⇒ Options
constructor
Initialize the options class.
-
#method_missing(method, *arguments, &block) ⇒ Object
Forwards all methods to the hash.
Constructor Details
#initialize(data) ⇒ Options
Initialize the options class.
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.
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.
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.
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 |