Class Ohai::Config
In: lib/ohai/config.rb
Parent: Object
Config System RuntimeError Exec Log\n[lib/ohai/log.rb\nlib/ohai/log/formatter.rb] lib/ohai/log/formatter.rb lib/ohai/config.rb lib/ohai/system.rb Command FromFile Mixin lib/ohai/exception.rb Exceptions Ohai dot/m_71_0.png

Methods

[]   []=   configure   has_key?   method_missing  

Included Modules

Ohai::Mixin::FromFile

Public Class methods

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

[Source]

    # File lib/ohai/config.rb, line 58
58:       def [](config_option)
59:         if @configuration.has_key?(config_option.to_sym)
60:           @configuration[config_option.to_sym]
61:         else
62:           raise ArgumentError, "Cannot find configuration option #{config_option.to_s}"
63:         end
64:       end

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

[Source]

    # File lib/ohai/config.rb, line 74
74:       def []=(config_option, value)
75:         @configuration[config_option.to_sym] = value
76:       end

Pass Ohai::Config.configure() a block, and it will yield @configuration.

Parameters

<block>:A block that takes @configure as its argument

[Source]

    # File lib/ohai/config.rb, line 44
44:       def configure(&block)
45:         yield @configuration
46:       end

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

[Source]

    # File lib/ohai/config.rb, line 86
86:       def has_key?(key)
87:         @configuration.has_key?(key.to_sym)
88:       end

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.

[Source]

     # File lib/ohai/config.rb, line 103
103:       def method_missing(method_symbol, *args)
104:         if @configuration.has_key?(method_symbol)
105:           if args.length == 1
106:             @configuration[method_symbol] = args[0]
107:           elsif args.length > 1
108:             @configuration[method_symbol] = args
109:           end
110:           return @configuration[method_symbol]
111:         else
112:           raise ArgumentError, "Cannot find configuration option #{method_symbol.to_s}"
113:         end
114:       end

[Validate]