Class: Qonfig::DataSet
Overview
Defined Under Namespace
Modules: ClassBuilder
Classes: Lock
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#[](key) ⇒ Object
-
#[]=(key, value) ⇒ void
-
#clear! ⇒ void
-
#compacted ⇒ Qonfig::Compacted
-
#configure(settings_map = {}) {|cofnig| ... } ⇒ void
-
#deep_each_setting(yield_all: false, &block) {|setting_key, setting_value| ... } ⇒ Enumerable
-
#dig(*keys) ⇒ Object
-
#dup ⇒ Qonfig::DataSet
-
#each_setting(&block) {|setting_key, setting_value| ... } ⇒ Enumerable
-
#export_settings(exportable_object, *exported_setting_keys, mappings: Qonfig::Imports::Mappings::EMPTY_MAPPINGS, raw: Qonfig::Imports::Abstract::DEFAULT_RAW_BEHAVIOR, prefix: Qonfig::Imports::Abstract::EMPTY_PREFIX, accessor: Qonfig::Imports::Abstract::AS_ACCESSOR) ⇒ void
-
#freeze! ⇒ void
-
#frozen? ⇒ void
-
#initialize(settings_map = {}, &configurations) ⇒ DataSet
constructor
A new instance of DataSet.
-
#key?(*key_path) ⇒ Boolean
(also: #option?, #setting?)
-
#keys(all_variants: false, only_root: false) ⇒ Array<String>
-
#load_from_file(file_path, format: :dynamic, strict: true, expose: nil, &configurations) ⇒ void
-
#load_from_json(file_path, strict: true, expose: nil, &configurations) ⇒ void
-
#load_from_self(format: :dynamic, strict: true, expose: nil, &configurations) ⇒ void
-
#load_from_toml(file_path, strict: true, expose: nil, &configuration) ⇒ void
-
#load_from_yaml(file_path, strict: true, expose: nil, &configurations) ⇒ void
-
#reload!(settings_map = {}, &configurations) ⇒ void
-
#root_keys ⇒ Array<String>
-
#save_to_json(path:, options: Qonfig::Uploaders::JSON::DEFAULT_OPTIONS, &value_processor) ⇒ void
(also: #dump_to_json)
-
#save_to_toml(path:, options: Qonfig::Uploaders::TOML::DEFAULT_OPTIONS, &value_processor) ⇒ void
(also: #dump_to_toml)
-
#save_to_yaml(path:, symbolize_keys: false, options: Qonfig::Uploaders::YAML::DEFAULT_OPTIONS, &value_processor) ⇒ void
(also: #dump_to_yaml)
-
#slice(*keys) ⇒ Hash
-
#slice_value(*keys) ⇒ Hash, Any
-
#subset(*keys) ⇒ Hash
private
-
#to_h(dot_style: Qonfig::Settings::REPRESENT_HASH_IN_DOT_STYLE, key_transformer: Qonfig::Settings::BASIC_SETTING_KEY_TRANSFORMER, value_transformer: Qonfig::Settings::BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash
(also: #to_hash)
-
#valid? ⇒ Boolean
-
#valid_with?(settings_map = {}, &configurations) ⇒ Boolean
-
#validate! ⇒ void
-
#with(temporary_configurations = {}, &arbitary_code) ⇒ void
Methods included from DSL
compose, define_validator, definition_commands, expose_json, expose_self, expose_toml, expose_vault, expose_yaml, extended, freeze_state!, instance_commands, load_from_env, load_from_vault, predefined_validators, re_setting, setting, validate, validators, values_file
#pretty_print
Constructor Details
#initialize(settings_map = {}, &configurations) ⇒ DataSet
Returns a new instance of DataSet.
64
65
66
67
|
# File 'lib/qonfig/data_set.rb', line 64
def initialize(settings_map = {}, &configurations)
@__lock__ = Qonfig::DataSet::Lock.new
thread_safe_definition { load!(settings_map, &configurations) }
end
|
Instance Attribute Details
57
58
59
|
# File 'lib/qonfig/data_set.rb', line 57
def settings
@settings
end
|
Class Method Details
.build(base_dataset_klass = self, &config_klass_definitions) ⇒ Qonfig::DataSet
20
21
22
23
24
25
26
|
# File 'lib/qonfig/data_set.rb', line 20
def build(base_dataset_klass = self, &config_klass_definitions)
unless base_dataset_klass <= Qonfig::DataSet
raise(Qonfig::ArgumentError, 'Base class should be a type of Qonfig::DataSet')
end
Class.new(base_dataset_klass, &config_klass_definitions).new
end
|
.build_compacted(base_dataset_klass = self, &config_klass_definitions) ⇒ Qonfig::Compacted
34
35
36
|
# File 'lib/qonfig/data_set.rb', line 34
def build_compacted(base_dataset_klass = self, &config_klass_definitions)
build(base_dataset_klass, &config_klass_definitions).compacted
end
|
.valid_with?(settings_map = {}, &configurations) ⇒ Boolean
45
46
47
48
49
50
|
# File 'lib/qonfig/data_set.rb', line 45
def valid_with?(settings_map = {}, &configurations)
new(settings_map, &configurations)
true
rescue Qonfig::ValidationError
false
end
|
Instance Method Details
#[](key) ⇒ Object
253
254
255
|
# File 'lib/qonfig/data_set.rb', line 253
def [](key)
thread_safe_access { settings[key] }
end
|
#[]=(key, value) ⇒ void
This method returns an undefined value.
267
268
269
|
# File 'lib/qonfig/data_set.rb', line 267
def []=(key, value)
thread_safe_access { settings[key] = value }
end
|
#clear! ⇒ void
This method returns an undefined value.
322
323
324
|
# File 'lib/qonfig/data_set.rb', line 322
def clear!
thread_safe_access { settings.__clear__ }
end
|
This method returns an undefined value.
181
182
183
184
185
|
# File 'lib/qonfig/data_set.rb', line 181
def configure(settings_map = {}, &configurations)
thread_safe_access do
apply_settings(settings_map, &configurations)
end
end
|
#deep_each_setting(yield_all: false, &block) {|setting_key, setting_value| ... } ⇒ Enumerable
349
350
351
|
# File 'lib/qonfig/data_set.rb', line 349
def deep_each_setting(yield_all: false, &block)
thread_safe_access { settings.__deep_each_setting__(yield_all: yield_all, &block) }
end
|
#dig(*keys) ⇒ Object
276
277
278
|
# File 'lib/qonfig/data_set.rb', line 276
def dig(*keys)
thread_safe_access { settings.__dig__(*keys) }
end
|
437
438
439
440
441
442
443
|
# File 'lib/qonfig/data_set.rb', line 437
def dup
thread_safe_definition do
self.class.build.tap do |duplicate|
duplicate.configure(to_h)
end
end
end
|
#each_setting(&block) {|setting_key, setting_value| ... } ⇒ Enumerable
335
336
337
|
# File 'lib/qonfig/data_set.rb', line 335
def each_setting(&block)
thread_safe_access { settings.__each_setting__(&block) }
end
|
#export_settings(exportable_object, *exported_setting_keys, mappings: Qonfig::Imports::Mappings::EMPTY_MAPPINGS, raw: Qonfig::Imports::Abstract::DEFAULT_RAW_BEHAVIOR, prefix: Qonfig::Imports::Abstract::EMPTY_PREFIX, accessor: Qonfig::Imports::Abstract::AS_ACCESSOR) ⇒ void
This method returns an undefined value.
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
# File 'lib/qonfig/data_set.rb', line 455
def export_settings(
exportable_object,
*exported_setting_keys,
mappings: Qonfig::Imports::Mappings::EMPTY_MAPPINGS,
raw: Qonfig::Imports::Abstract::DEFAULT_RAW_BEHAVIOR,
prefix: Qonfig::Imports::Abstract::EMPTY_PREFIX,
accessor: Qonfig::Imports::Abstract::AS_ACCESSOR
)
thread_safe_access do
Qonfig::Imports::Export.export!(
exportable_object,
self,
*exported_setting_keys,
prefix: prefix,
raw: raw,
mappings: mappings,
accessor: accessor
)
end
end
|
#freeze! ⇒ void
This method returns an undefined value.
73
74
75
|
# File 'lib/qonfig/data_set.rb', line 73
def freeze!
thread_safe_access { settings.__freeze__ }
end
|
#frozen? ⇒ void
This method returns an undefined value.
81
82
83
|
# File 'lib/qonfig/data_set.rb', line 81
def frozen?
thread_safe_access { settings.__is_frozen__ }
end
|
#key?(*key_path) ⇒ Boolean
Also known as:
option?, setting?
312
313
314
|
# File 'lib/qonfig/data_set.rb', line 312
def key?(*key_path)
thread_safe_access { settings.__has_key__(*key_path) }
end
|
#keys(all_variants: false, only_root: false) ⇒ Array<String>
396
397
398
399
400
|
# File 'lib/qonfig/data_set.rb', line 396
def keys(all_variants: false, only_root: false)
thread_safe_access do
only_root ? settings.__root_keys__ : settings.__keys__(all_variants: all_variants)
end
end
|
#load_from_file(file_path, format: :dynamic, strict: true, expose: nil, &configurations) ⇒ void
This method returns an undefined value.
112
113
114
115
116
117
118
|
# File 'lib/qonfig/data_set.rb', line 112
def load_from_file(file_path, format: :dynamic, strict: true, expose: nil, &configurations)
thread_safe_access do
load_setting_values_from_file(
file_path, format: format, strict: strict, expose: expose, &configurations
)
end
end
|
#load_from_json(file_path, strict: true, expose: nil, &configurations) ⇒ void
This method returns an undefined value.
146
147
148
|
# File 'lib/qonfig/data_set.rb', line 146
def load_from_json(file_path, strict: true, expose: nil, &configurations)
load_from_file(file_path, format: :json, strict: strict, expose: expose, &configurations)
end
|
#load_from_self(format: :dynamic, strict: true, expose: nil, &configurations) ⇒ void
This method returns an undefined value.
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/qonfig/data_set.rb', line 159
def load_from_self(format: :dynamic, strict: true, expose: nil, &configurations)
caller_location = ::Kernel.caller(1, 1).first
thread_safe_access do
load_setting_values_from_file(
:self,
format: format,
strict: strict,
expose: expose,
caller_location: caller_location,
&configurations
)
end
end
|
#load_from_toml(file_path, strict: true, expose: nil, &configuration) ⇒ void
This method returns an undefined value.
31
32
33
|
# File 'lib/qonfig/plugins/toml/data_set.rb', line 31
def load_from_toml(file_path, strict: true, expose: nil, &configuration)
load_from_file(file_path, format: :toml, strict: strict, expose: expose, &configuration)
end
|
#load_from_yaml(file_path, strict: true, expose: nil, &configurations) ⇒ void
This method returns an undefined value.
131
132
133
|
# File 'lib/qonfig/data_set.rb', line 131
def load_from_yaml(file_path, strict: true, expose: nil, &configurations)
load_from_file(file_path, format: :yml, strict: strict, expose: expose, &configurations)
end
|
#reload!(settings_map = {}, &configurations) ⇒ void
This method returns an undefined value.
93
94
95
96
97
98
|
# File 'lib/qonfig/data_set.rb', line 93
def reload!(settings_map = {}, &configurations)
thread_safe_definition do
raise Qonfig::FrozenSettingsError, 'Frozen config can not be reloaded' if frozen?
load!(settings_map, &configurations)
end
end
|
#root_keys ⇒ Array<String>
406
407
408
|
# File 'lib/qonfig/data_set.rb', line 406
def root_keys
thread_safe_access { settings.__root_keys__ }
end
|
#save_to_json(path:, options: Qonfig::Uploaders::JSON::DEFAULT_OPTIONS, &value_processor) ⇒ void
Also known as:
dump_to_json
This method returns an undefined value.
#save_to_toml(path:, options: Qonfig::Uploaders::TOML::DEFAULT_OPTIONS, &value_processor) ⇒ void
Also known as:
dump_to_toml
This method returns an undefined value.
#save_to_yaml(path:, symbolize_keys: false, options: Qonfig::Uploaders::YAML::DEFAULT_OPTIONS, &value_processor) ⇒ void
Also known as:
dump_to_yaml
This method returns an undefined value.
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/qonfig/data_set.rb', line 231
def save_to_yaml(
path:,
symbolize_keys: false,
options: Qonfig::Uploaders::YAML::DEFAULT_OPTIONS,
&value_processor
)
thread_safe_access do
Qonfig::Uploaders::YAML.upload(
settings,
path: path,
options: options.merge(symbolize_keys: symbolize_keys),
&value_processor
)
end
end
|
#slice(*keys) ⇒ Hash
285
286
287
|
# File 'lib/qonfig/data_set.rb', line 285
def slice(*keys)
thread_safe_access { settings.__slice__(*keys) }
end
|
#slice_value(*keys) ⇒ Hash, Any
294
295
296
|
# File 'lib/qonfig/data_set.rb', line 294
def slice_value(*keys)
thread_safe_access { settings.__slice_value__(*keys) }
end
|
#subset(*keys) ⇒ Hash
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
303
304
305
|
# File 'lib/qonfig/data_set.rb', line 303
def subset(*keys)
thread_safe_access { settings.__subset__(*keys) }
end
|
#to_h(dot_style: Qonfig::Settings::REPRESENT_HASH_IN_DOT_STYLE, key_transformer: Qonfig::Settings::BASIC_SETTING_KEY_TRANSFORMER, value_transformer: Qonfig::Settings::BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash
Also known as:
to_hash
#valid? ⇒ Boolean
357
358
359
|
# File 'lib/qonfig/data_set.rb', line 357
def valid?
thread_safe_access { validator.valid? }
end
|
#valid_with?(settings_map = {}, &configurations) ⇒ Boolean
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
# File 'lib/qonfig/data_set.rb', line 367
def valid_with?(settings_map = {}, &configurations)
dup.configure(settings_map, &configurations)
true
rescue Qonfig::ValidationError
false
end
|
#validate! ⇒ void
This method returns an undefined value.
386
387
388
|
# File 'lib/qonfig/data_set.rb', line 386
def validate!
thread_safe_access { validator.validate! }
end
|
#with(temporary_configurations = {}, &arbitary_code) ⇒ void
This method returns an undefined value.
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
# File 'lib/qonfig/data_set.rb', line 416
def with(temporary_configurations = {}, &arbitary_code)
with_arbitary_access do
begin
original_settings = @settings
temporary_settings = self.class.build.dup.tap do |copied_config|
copied_config.configure(temporary_configurations)
end.settings
@settings = temporary_settings
yield if block_given?
ensure
@settings = original_settings
end
end
end
|