Class: Ohai::Config
- Inherits:
-
Object
- Object
- Ohai::Config
- Extended by:
- Mixin::FromFile
- Defined in:
- lib/ohai/config.rb
Class Method Summary collapse
-
.[](config_option) ⇒ Object
Get the value of a configuration option.
-
.[]=(config_option, value) ⇒ Object
Set the value of a configuration option.
-
.configure {|@configuration| ... } ⇒ Object
Pass Ohai::Config.configure() a block, and it will yield @configuration.
-
.has_key?(key) ⇒ Boolean
Check if Ohai::Config has a configuration option.
-
.method_missing(method_symbol, *args) ⇒ Object
Allows for simple lookups and setting of configuration options via method calls on Ohai::Config.
Methods included from Mixin::FromFile
Class Method Details
.[](config_option) ⇒ Object
Get the value of a configuration option
Parameters
- config_option<Symbol>
-
The configuration option to return
Returns
- value
-
The value of the configuration option
Raises
- <ArgumentError>
-
If the configuration option does not exist
58 59 60 61 62 63 64 |
# File 'lib/ohai/config.rb', line 58 def [](config_option) if @configuration.has_key?(config_option.to_sym) @configuration[config_option.to_sym] else raise ArgumentError, "Cannot find configuration option #{config_option.to_s}" end end |
.[]=(config_option, value) ⇒ Object
Set the value of a configuration option
Parameters
- config_option<Symbol>
-
The configuration option to set (within the [])
- value
-
The value for the configuration option
Returns
- value
-
The new value of the configuration option
74 75 76 |
# File 'lib/ohai/config.rb', line 74 def []=(config_option, value) @configuration[config_option.to_sym] = value end |
.configure {|@configuration| ... } ⇒ Object
Pass Ohai::Config.configure() a block, and it will yield @configuration.
Parameters
- <block>
-
A block that takes @configure as its argument
44 45 46 |
# File 'lib/ohai/config.rb', line 44 def configure(&block) yield @configuration end |
.has_key?(key) ⇒ Boolean
Check if Ohai::Config has a configuration option.
Parameters
- key<Symbol>
-
The configuration option to check for
Returns
- <True>
-
If the configuration option exists
- <False>
-
If the configuration option does not exist
86 87 88 |
# File 'lib/ohai/config.rb', line 86 def has_key?(key) @configuration.has_key?(key.to_sym) end |
.method_missing(method_symbol, *args) ⇒ Object
Allows for simple lookups and setting of configuration options via method calls on Ohai::Config. If there any arguments to the method, they are used to set the value of the configuration option. Otherwise, it’s a simple get operation.
Parameters
- method_symbol<Symbol>
-
The method called. Must match a configuration option.
- *args
-
Any arguments passed to the method
Returns
- value
-
The value of the configuration option.
Raises
- <ArgumentError>
-
If the method_symbol does not match a configuration option.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ohai/config.rb', line 103 def method_missing(method_symbol, *args) if @configuration.has_key?(method_symbol) if args.length == 1 @configuration[method_symbol] = args[0] elsif args.length > 1 @configuration[method_symbol] = args end return @configuration[method_symbol] else raise ArgumentError, "Cannot find configuration option #{method_symbol.to_s}" end end |