Class: Coral::Config
- Inherits:
-
Object
- Object
- Coral::Config
- Extended by:
- Mixin::ConfigCollection, Mixin::ConfigOps, Mixin::ConfigOptions, Mixin::Lookup
- Defined in:
- lib/coral_core/config.rb,
lib/coral_core/config/options.rb,
lib/coral_core/config/project.rb,
lib/coral_core/config/collection.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Collection, Options, Project
Class Method Summary collapse
-
.array(data, default = [], split_string = false) ⇒ Object
—————————————————————————–.
-
.ensure(config) ⇒ Object
—————————————————————————– Instance generators.
-
.filter(data, method = false) ⇒ Object
—————————————————————————–.
-
.hash(data, default = {}) ⇒ Object
—.
-
.init(options, contexts = [], hierarchy = [], defaults = {}) ⇒ Object
—.
-
.init_flat(options, contexts = [], defaults = {}) ⇒ Object
—.
-
.string(data, default = '') ⇒ Object
—.
-
.string_map(data) ⇒ Object
—.
-
.symbol(data, default = :undefined) ⇒ Object
—.
-
.symbol_map(data) ⇒ Object
—————————————————————————– Utilities.
-
.test(data) ⇒ Object
—.
Instance Method Summary collapse
-
#[](name, default = nil, format = false) ⇒ Object
—.
-
#[]=(name, value) ⇒ Object
—.
-
#array(data, default = [], split_string = false) ⇒ Object
—.
-
#clear ⇒ Object
—.
-
#defaults(defaults, options = {}) ⇒ Object
—.
-
#delete(keys, default = nil) ⇒ Object
—.
-
#export ⇒ Object
—.
-
#filter(data, method = false) ⇒ Object
—.
-
#get(keys, default = nil, format = false) ⇒ Object
—.
-
#get_array(keys, default = []) ⇒ Object
—.
-
#get_hash(keys, default = {}) ⇒ Object
—.
-
#hash(data, default = {}) ⇒ Object
—.
-
#import(properties, options = {}) ⇒ Object
—.
-
#init(keys, default = nil) ⇒ Object
—.
-
#initialize(data = {}, defaults = {}, force = true) ⇒ Config
constructor
—————————————————————————– Constructor / Destructor.
-
#set(keys, value) ⇒ Object
—.
-
#string(data, default = '') ⇒ Object
—.
-
#string_map(data) ⇒ Object
—.
-
#symbol(data, default = :undefined) ⇒ Object
—.
-
#symbol_map(data) ⇒ Object
—.
-
#test(data) ⇒ Object
—.
Methods included from Mixin::ConfigOptions
clear_options, contexts, get_options, set_options
Methods included from Mixin::ConfigCollection
all_properties, clear_properties, delete_property, get_property, save_properties, set_property
Methods included from Mixin::Lookup
hiera, hiera_config, initialized?, lookup, lookup_array, lookup_hash, normalize
Methods included from Mixin::ConfigOps
Constructor Details
#initialize(data = {}, defaults = {}, force = true) ⇒ Config
Constructor / Destructor
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/coral_core/config.rb', line 44 def initialize(data = {}, defaults = {}, force = true) @force = force @properties = {} if defaults.is_a?(Hash) && ! defaults.empty? defaults = symbol_map(defaults) end case data when Coral::Config @properties = Util::Data.merge([ defaults, data.export ], force) when Hash @properties = {} if data.is_a?(Hash) @properties = Util::Data.merge([ defaults, symbol_map(data) ], force) end end end |
Class Method Details
.array(data, default = [], split_string = false) ⇒ Object
270 271 272 |
# File 'lib/coral_core/config.rb', line 270 def self.array(data, default = [], split_string = false) return Util::Data.array(data, default, split_string) end |
.ensure(config) ⇒ Object
Instance generators
16 17 18 19 20 21 22 23 24 |
# File 'lib/coral_core/config.rb', line 16 def self.ensure(config) case config when Coral::Config return config when Hash return new(config) end return new end |
.filter(data, method = false) ⇒ Object
258 259 260 |
# File 'lib/coral_core/config.rb', line 258 def self.filter(data, method = false) return Util::Data.filter(data, method) end |
.hash(data, default = {}) ⇒ Object
282 283 284 285 |
# File 'lib/coral_core/config.rb', line 282 def self.hash(data, default = {}) data = data.export if data.is_a?(Coral::Config) return Util::Data.hash(data, default) end |
.init(options, contexts = [], hierarchy = [], defaults = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/coral_core/config.rb', line 28 def self.init(, contexts = [], hierarchy = [], defaults = {}) contexts = contexts(contexts, hierarchy) config = new((contexts), defaults) config.import() unless Util::Data.empty?() return config end |
.init_flat(options, contexts = [], defaults = {}) ⇒ Object
37 38 39 |
# File 'lib/coral_core/config.rb', line 37 def self.init_flat(, contexts = [], defaults = {}) return init(, contexts, [], defaults) end |
.string(data, default = '') ⇒ Object
295 296 297 |
# File 'lib/coral_core/config.rb', line 295 def self.string(data, default = '') return Util::Data.string(data, default) end |
.string_map(data) ⇒ Object
246 247 248 |
# File 'lib/coral_core/config.rb', line 246 def self.string_map(data) return Util::Data.string_map(data) end |
.symbol(data, default = :undefined) ⇒ Object
307 308 309 |
# File 'lib/coral_core/config.rb', line 307 def self.symbol(data, default = :undefined) return Util::Data.symbol(data, default) end |
.symbol_map(data) ⇒ Object
Utilities
234 235 236 |
# File 'lib/coral_core/config.rb', line 234 def self.symbol_map(data) return Util::Data.symbol_map(data) end |
Instance Method Details
#[](name, default = nil, format = false) ⇒ Object
130 131 132 |
# File 'lib/coral_core/config.rb', line 130 def [](name, default = nil, format = false) get(name, default, format) end |
#[]=(name, value) ⇒ Object
161 162 163 |
# File 'lib/coral_core/config.rb', line 161 def []=(name, value) set(name, value) end |
#array(data, default = [], split_string = false) ⇒ Object
276 277 278 |
# File 'lib/coral_core/config.rb', line 276 def array(data, default = [], split_string = false) return self.class.array(data, default, split_string) end |
#clear ⇒ Object
175 176 177 178 |
# File 'lib/coral_core/config.rb', line 175 def clear @properties = {} return self end |
#defaults(defaults, options = {}) ⇒ Object
220 221 222 223 |
# File 'lib/coral_core/config.rb', line 220 def defaults(defaults, = {}) config = new().set(:import_type, :default) return import_base(defaults, config) end |
#delete(keys, default = nil) ⇒ Object
167 168 169 170 171 |
# File 'lib/coral_core/config.rb', line 167 def delete(keys, default = nil) existing = modify(@properties, array(keys).flatten, nil) return existing[:value] if existing[:value] return default end |
#export ⇒ Object
227 228 229 |
# File 'lib/coral_core/config.rb', line 227 def export return @properties end |
#filter(data, method = false) ⇒ Object
264 265 266 |
# File 'lib/coral_core/config.rb', line 264 def filter(data, method = false) return self.class.filter(data, method) end |
#get(keys, default = nil, format = false) ⇒ Object
124 125 126 |
# File 'lib/coral_core/config.rb', line 124 def get(keys, default = nil, format = false) return fetch(@properties, array(keys).flatten, default, format) end |
#get_array(keys, default = []) ⇒ Object
136 137 138 |
# File 'lib/coral_core/config.rb', line 136 def get_array(keys, default = []) return get(keys, default, :array) end |
#get_hash(keys, default = {}) ⇒ Object
142 143 144 |
# File 'lib/coral_core/config.rb', line 142 def get_hash(keys, default = {}) return get(keys, default, :hash) end |
#hash(data, default = {}) ⇒ Object
289 290 291 |
# File 'lib/coral_core/config.rb', line 289 def hash(data, default = {}) return self.class.hash(data, default) end |
#import(properties, options = {}) ⇒ Object
214 215 216 |
# File 'lib/coral_core/config.rb', line 214 def import(properties, = {}) return import_base(properties, ) end |
#init(keys, default = nil) ⇒ Object
148 149 150 |
# File 'lib/coral_core/config.rb', line 148 def init(keys, default = nil) return set(keys, get(keys, default)) end |
#set(keys, value) ⇒ Object
154 155 156 157 |
# File 'lib/coral_core/config.rb', line 154 def set(keys, value) modify(@properties, array(keys).flatten, value) return self end |
#string(data, default = '') ⇒ Object
301 302 303 |
# File 'lib/coral_core/config.rb', line 301 def string(data, default = '') return self.class.string(data, default) end |
#string_map(data) ⇒ Object
252 253 254 |
# File 'lib/coral_core/config.rb', line 252 def string_map(data) return self.class.string_map(data) end |
#symbol(data, default = :undefined) ⇒ Object
313 314 315 |
# File 'lib/coral_core/config.rb', line 313 def symbol(data, default = :undefined) return self.class.symbol(data, default) end |
#symbol_map(data) ⇒ Object
240 241 242 |
# File 'lib/coral_core/config.rb', line 240 def symbol_map(data) return self.class.symbol_map(data) end |
#test(data) ⇒ Object
325 326 327 |
# File 'lib/coral_core/config.rb', line 325 def test(data) return self.class.test(data) end |