Class: Nucleon::Config
- Inherits:
-
Object
- Object
- Nucleon::Config
- Extended by:
- Mixin::ConfigCollection, Mixin::ConfigOptions
- Defined in:
- lib/core/config.rb,
lib/core/config/options.rb,
lib/core/config/collection.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Collection, Options
Class Method Summary collapse
-
.array(data, default = [], split_string = false) ⇒ Object
—————————————————————————–.
-
.ensure(config, defaults = {}, force = true, basic_merge = true) ⇒ Object
—————————————————————————– Instance generators.
-
.filter(data, method = false) ⇒ Object
—————————————————————————–.
-
.hash(data, default = {}) ⇒ Object
—.
-
.init(options, contexts = [], hierarchy = [], defaults = {}, force = true, basic_merge = true) ⇒ Object
—.
-
.init_flat(options, contexts = [], defaults = {}, force = true, basic_merge = true) ⇒ 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
—.
-
#empty? ⇒ Boolean
—————————————————————————– Checks.
-
#export ⇒ Object
—.
-
#filter(data, method = false) ⇒ Object
—.
-
#get(keys, default = nil, format = false) ⇒ Object
—.
-
#get_array(keys, default = []) ⇒ Object
—.
-
#get_hash(keys, default = {}) ⇒ Object
—.
-
#has_key?(keys) ⇒ Boolean
—.
-
#hash(data, default = {}) ⇒ Object
—.
-
#import(properties, options = {}) ⇒ Object
—.
-
#init(keys, default = nil) ⇒ Object
—.
-
#initialize(data = {}, defaults = {}, force = true, basic_merge = true) ⇒ Config
constructor
—————————————————————————– Constructor / Destructor.
-
#keys ⇒ Object
—————————————————————————– Property accessors / modifiers.
-
#set(keys, value, delete_nil = false) ⇒ 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
all_options, clear_options, contexts, get_options, set_options
Methods included from Mixin::ConfigCollection
all_properties, clear_properties, delete_property, get_property, save_properties, set_property
Constructor Details
#initialize(data = {}, defaults = {}, force = true, basic_merge = true) ⇒ Config
Constructor / Destructor
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/core/config.rb', line 42 def initialize(data = {}, defaults = {}, force = true, basic_merge = true) @force = force @basic_merge = basic_merge @properties = {} if defaults.is_a?(Hash) && ! defaults.empty? defaults = symbol_map(defaults.clone) end case data when Nucleon::Config @properties = Util::Data.merge([ defaults, data.export ], force, basic_merge) when Hash @properties = {} if data.is_a?(Hash) @properties = Util::Data.merge([ defaults, symbol_map(data.clone) ], force, basic_merge) end end end |
Class Method Details
.array(data, default = [], split_string = false) ⇒ Object
292 293 294 |
# File 'lib/core/config.rb', line 292 def self.array(data, default = [], split_string = false) return Util::Data.array(data, default, split_string) end |
.ensure(config, defaults = {}, force = true, basic_merge = true) ⇒ Object
Instance generators
14 15 16 17 18 19 20 21 22 |
# File 'lib/core/config.rb', line 14 def self.ensure(config, defaults = {}, force = true, basic_merge = true) case config when Nucleon::Config return config.defaults(defaults) when Hash return new(config, defaults, force, basic_merge) end return new({}, defaults, force, basic_merge) end |
.filter(data, method = false) ⇒ Object
280 281 282 |
# File 'lib/core/config.rb', line 280 def self.filter(data, method = false) return Util::Data.filter(data, method) end |
.hash(data, default = {}) ⇒ Object
304 305 306 307 |
# File 'lib/core/config.rb', line 304 def self.hash(data, default = {}) data = data.export if data.is_a?(Nucleon::Config) return Util::Data.hash(data, default) end |
.init(options, contexts = [], hierarchy = [], defaults = {}, force = true, basic_merge = true) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/core/config.rb', line 26 def self.init(, contexts = [], hierarchy = [], defaults = {}, force = true, basic_merge = true) contexts = contexts(contexts, hierarchy) config = new((contexts), defaults, force, basic_merge) config.import() unless Util::Data.empty?() return config end |
.init_flat(options, contexts = [], defaults = {}, force = true, basic_merge = true) ⇒ Object
35 36 37 |
# File 'lib/core/config.rb', line 35 def self.init_flat(, contexts = [], defaults = {}, force = true, basic_merge = true) return init(, contexts, [], defaults, force, basic_merge) end |
.string(data, default = '') ⇒ Object
317 318 319 |
# File 'lib/core/config.rb', line 317 def self.string(data, default = '') return Util::Data.string(data, default) end |
.string_map(data) ⇒ Object
268 269 270 |
# File 'lib/core/config.rb', line 268 def self.string_map(data) return Util::Data.string_map(data) end |
.symbol(data, default = :undefined) ⇒ Object
329 330 331 |
# File 'lib/core/config.rb', line 329 def self.symbol(data, default = :undefined) return Util::Data.symbol(data, default) end |
.symbol_map(data) ⇒ Object
Utilities
256 257 258 |
# File 'lib/core/config.rb', line 256 def self.symbol_map(data) return Util::Data.symbol_map(data) end |
Instance Method Details
#[](name, default = nil, format = false) ⇒ Object
150 151 152 |
# File 'lib/core/config.rb', line 150 def [](name, default = nil, format = false) get(name, default, format) end |
#[]=(name, value) ⇒ Object
181 182 183 |
# File 'lib/core/config.rb', line 181 def []=(name, value) set(name, value) end |
#array(data, default = [], split_string = false) ⇒ Object
298 299 300 |
# File 'lib/core/config.rb', line 298 def array(data, default = [], split_string = false) return self.class.array(data, default, split_string) end |
#clear ⇒ Object
195 196 197 198 |
# File 'lib/core/config.rb', line 195 def clear @properties = {} return self end |
#defaults(defaults, options = {}) ⇒ Object
242 243 244 245 |
# File 'lib/core/config.rb', line 242 def defaults(defaults, = {}) config = Config.new().set(:import_type, :default) return import_base(defaults, config) end |
#delete(keys, default = nil) ⇒ Object
187 188 189 190 191 |
# File 'lib/core/config.rb', line 187 def delete(keys, default = nil) existing = modify(@properties, array(keys).flatten, nil, true) return existing[:value] unless existing[:value].nil? return default end |
#empty? ⇒ Boolean
Checks
65 66 67 |
# File 'lib/core/config.rb', line 65 def empty? @properties.empty? end |
#export ⇒ Object
249 250 251 |
# File 'lib/core/config.rb', line 249 def export return @properties.clone end |
#filter(data, method = false) ⇒ Object
286 287 288 |
# File 'lib/core/config.rb', line 286 def filter(data, method = false) return self.class.filter(data, method) end |
#get(keys, default = nil, format = false) ⇒ Object
144 145 146 |
# File 'lib/core/config.rb', line 144 def get(keys, default = nil, format = false) return fetch(@properties, array(keys).flatten, default, format) end |
#get_array(keys, default = []) ⇒ Object
156 157 158 |
# File 'lib/core/config.rb', line 156 def get_array(keys, default = []) return get(keys, default, :array) end |
#get_hash(keys, default = {}) ⇒ Object
162 163 164 |
# File 'lib/core/config.rb', line 162 def get_hash(keys, default = {}) return get(keys, default, :hash) end |
#has_key?(keys) ⇒ Boolean
71 72 73 |
# File 'lib/core/config.rb', line 71 def has_key?(keys) get(keys).nil? ? false : true end |
#hash(data, default = {}) ⇒ Object
311 312 313 |
# File 'lib/core/config.rb', line 311 def hash(data, default = {}) return self.class.hash(data, default) end |
#import(properties, options = {}) ⇒ Object
236 237 238 |
# File 'lib/core/config.rb', line 236 def import(properties, = {}) return import_base(properties, ) end |
#init(keys, default = nil) ⇒ Object
168 169 170 |
# File 'lib/core/config.rb', line 168 def init(keys, default = nil) return set(keys, get(keys, default)) end |
#keys ⇒ Object
Property accessors / modifiers
78 79 80 |
# File 'lib/core/config.rb', line 78 def keys @properties.keys end |
#set(keys, value, delete_nil = false) ⇒ Object
174 175 176 177 |
# File 'lib/core/config.rb', line 174 def set(keys, value, delete_nil = false) modify(@properties, array(keys).flatten, value, delete_nil) return self end |
#string(data, default = '') ⇒ Object
323 324 325 |
# File 'lib/core/config.rb', line 323 def string(data, default = '') return self.class.string(data, default) end |
#string_map(data) ⇒ Object
274 275 276 |
# File 'lib/core/config.rb', line 274 def string_map(data) return self.class.string_map(data) end |
#symbol(data, default = :undefined) ⇒ Object
335 336 337 |
# File 'lib/core/config.rb', line 335 def symbol(data, default = :undefined) return self.class.symbol(data, default) end |
#symbol_map(data) ⇒ Object
262 263 264 |
# File 'lib/core/config.rb', line 262 def symbol_map(data) return self.class.symbol_map(data) end |
#test(data) ⇒ Object
347 348 349 |
# File 'lib/core/config.rb', line 347 def test(data) return self.class.test(data) end |