class Wright::Config
Configuration container, wraps a regular Ruby hash.
Useful for getting and setting configuration values, such as logging verbosity, color output and provider configuration.
@example
Wright::Config[:foo] = { bar: :baz } Wright::Config[:foo][:bar] # => :baz
Attributes
config_hash[R]
Public Class Methods
nested_key?(*path)
click to toggle source
Checks if a (nested) configuration value is set.
@param path [Array<Symbol>] the configuration key
@example
Wright::Config[:foo] = { bar: :baz } Wright::Config.nested_key?(:foo, :bar) # => true Wright::Config.nested_key?(:this, :doesnt, :exist) # => false
@return [Bool] true if the configuration value is set and false
otherwise.
# File lib/wright/config.rb, line 37 def self.nested_key?(*path) last_key = path.pop last_hash = path.reduce(config_hash) do |hash, key| return false unless hash.respond_to?(:fetch) hash.fetch(key, {}) end last_hash.respond_to?(:key?) && last_hash.key?(last_key) end
nested_value(*path)
click to toggle source
Retrieves a (nested) configuration value.
@param path [Array<Symbol>] the configuration key
@example
Wright::Config[:foo] = { bar: :baz } Wright::Config.nested_value(:foo, :bar) # => :baz Wright::Config.nested_value(:this, :doesnt, :exist) # => nil
@return the configuration value or nil if the value is not set
# File lib/wright/config.rb, line 59 def self.nested_value(*path) nested_key?(*path) ? path.reduce(config_hash) { |a, e| a[e] } : nil end