Class: SleepingKingStudios::Tools::Toolbox::Configuration
- Inherits:
-
Object
- Object
- SleepingKingStudios::Tools::Toolbox::Configuration
- Extended by:
- ClassMethods
- Defined in:
- lib/sleeping_king_studios/tools/toolbox/configuration.rb
Overview
Abstract base class for defining configuration objects.
Direct Known Subclasses
SleepingKingStudios::Tasks::Apps::AppConfiguration, SleepingKingStudios::Tasks::Configuration
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_OPTION =
ClassMethods::DEFAULT_OPTION
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #dig(*keys) ⇒ Object
- #fetch(key, default = DEFAULT_OPTION) ⇒ Object
-
#initialize(data = nil) {|The| ... } ⇒ Configuration
constructor
A new instance of Configuration.
Methods included from ClassMethods
Constructor Details
#initialize(data = nil) {|The| ... } ⇒ Configuration
Returns a new instance of Configuration.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 125 def initialize(data = nil) @data = convert_data_to_struct(data) @root_namespace = self return unless block_given? SleepingKingStudios::Tools::CoreTools .deprecate('Configuration#initialize with a block') yield(singleton_class) end |
Instance Method Details
#[](key) ⇒ Object
137 138 139 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 137 def [](key) send(key) if respond_to?(key) end |
#[]=(key, value) ⇒ Object
141 142 143 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 141 def []=(key, value) send(:"#{key}=", value) if respond_to?(key) end |
#dig(*keys) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 145 def dig(*keys) keys.reduce(self) do |config, key| value = config[key] return value if value.nil? value end end |
#fetch(key, default = DEFAULT_OPTION) ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/sleeping_king_studios/tools/toolbox/configuration.rb', line 155 def fetch(key, default = DEFAULT_OPTION) return send(key) if respond_to?(key) return default unless default == DEFAULT_OPTION return yield(key) if block_given? raise KeyError, "key not found: #{key.inspect}" end |