Class: Wright::Config
- Inherits:
-
Object
- Object
- Wright::Config
- Extended by:
- Forwardable
- Defined in:
- lib/wright/config.rb
Overview
Configuration container, wraps a regular Ruby hash.
Useful for getting and setting configuration values, such as logging verbosity, color output and provider configuration.
Class Attribute Summary collapse
-
.config_hash ⇒ Object
readonly
Returns the value of attribute config_hash.
Class Method Summary collapse
-
.nested_key?(*path) ⇒ Bool
Checks if a (nested) configuration value is set.
-
.nested_value(*path) ⇒ Object
Retrieves a (nested) configuration value.
Class Attribute Details
.config_hash ⇒ Object (readonly)
Returns the value of attribute config_hash.
18 19 20 |
# File 'lib/wright/config.rb', line 18 def config_hash @config_hash end |
Class Method Details
.nested_key?(*path) ⇒ Bool
Checks if a (nested) configuration value is set.
37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
Retrieves a (nested) configuration value.
59 60 61 |
# 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 |