Class: Qonfig::DataSet
- Inherits:
-
Object
show all
- Extended by:
- DSL, Validator::DSL
- Defined in:
- lib/qonfig/data_set.rb,
lib/qonfig/plugins/toml/data_set.rb
Overview
Defined Under Namespace
Modules: ClassBuilder
Classes: Lock
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#[](key) ⇒ Object
-
#clear! ⇒ void
-
#configure(settings_map = {}, &configurations) ⇒ void
-
#deep_each_setting(&block) {|setting_key, setting_value| ... } ⇒ Enumerable
-
#dig(*keys) ⇒ Object
-
#dup ⇒ Qonfig::DataSet
-
#each_setting(&block) {|setting_key, setting_value| ... } ⇒ Enumerable
-
#freeze! ⇒ void
-
#frozen? ⇒ void
-
#initialize(settings_map = {}, &configurations) ⇒ DataSet
constructor
A new instance of DataSet.
-
#key?(*key_path) ⇒ Boolean
(also: #option?, #setting?)
-
#load_from_file(file_path, format: :dynamic, strict: true, expose: nil) ⇒ void
-
#load_from_json(file_path, strict: true, expose: nil) ⇒ void
-
#load_from_self(format: :dynamic, strict: true, expose: nil) ⇒ void
-
#load_from_toml(file_path, strict: true, expose: nil) ⇒ void
-
#load_from_yaml(file_path, strict: true, expose: nil) ⇒ void
-
#reload!(settings_map = {}, &configurations) ⇒ void
-
#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(key_transformer: Qonfig::Settings::BASIC_SETTING_KEY_TRANSFORMER, value_transformer: Qonfig::Settings::BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash
(also: #to_hash)
-
#valid? ⇒ Boolean
-
#validate! ⇒ void
-
#with(temporary_configurations = {}, &arbitary_code) ⇒ void
Methods included from DSL
compose, definition_commands, expose_json, expose_self, expose_toml, expose_yaml, extended, instance_commands, load_from_env, setting, values_file
extended, validate, validators
Constructor Details
#initialize(settings_map = {}, &configurations) ⇒ DataSet
Returns a new instance of DataSet.
42
43
44
45
|
# File 'lib/qonfig/data_set.rb', line 42
def initialize(settings_map = {}, &configurations)
@__lock__ = Qonfig::DataSet::Lock.new
thread_safe_definition { load!(settings_map, &configurations) }
end
|
Instance Attribute Details
35
36
37
|
# File 'lib/qonfig/data_set.rb', line 35
def settings
@settings
end
|
Class Method Details
.build(base_dataset_klass = self, &config_klass_definitions) ⇒ Qonfig::DataSet
22
23
24
25
26
27
28
|
# File 'lib/qonfig/data_set.rb', line 22
def build(base_dataset_klass = self, &config_klass_definitions)
unless base_dataset_klass <= Qonfig::DataSet
raise(Qonfig::ArgumentError, 'Base inherited class should be a type of Qonfig::DataSet')
end
Class.new(base_dataset_klass, &config_klass_definitions).new
end
|
Instance Method Details
#[](key) ⇒ Object
211
212
213
|
# File 'lib/qonfig/data_set.rb', line 211
def [](key)
thread_safe_access { settings[key] }
end
|
#clear! ⇒ void
This method returns an undefined value.
266
267
268
|
# File 'lib/qonfig/data_set.rb', line 266
def clear!
thread_safe_access { settings.__clear__ }
end
|
This method returns an undefined value.
142
143
144
145
146
|
# File 'lib/qonfig/data_set.rb', line 142
def configure(settings_map = {}, &configurations)
thread_safe_access do
apply_settings(settings_map, &configurations)
end
end
|
#deep_each_setting(&block) {|setting_key, setting_value| ... } ⇒ Enumerable
292
293
294
|
# File 'lib/qonfig/data_set.rb', line 292
def deep_each_setting(&block)
thread_safe_access { settings.__deep_each_setting__(&block) }
end
|
#dig(*keys) ⇒ Object
220
221
222
|
# File 'lib/qonfig/data_set.rb', line 220
def dig(*keys)
thread_safe_access { settings.__dig__(*keys) }
end
|
339
340
341
342
343
344
345
|
# File 'lib/qonfig/data_set.rb', line 339
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
279
280
281
|
# File 'lib/qonfig/data_set.rb', line 279
def each_setting(&block)
thread_safe_access { settings.__each_setting__(&block) }
end
|
#freeze! ⇒ void
This method returns an undefined value.
51
52
53
|
# File 'lib/qonfig/data_set.rb', line 51
def freeze!
thread_safe_access { settings.__freeze__ }
end
|
#frozen? ⇒ void
This method returns an undefined value.
59
60
61
|
# File 'lib/qonfig/data_set.rb', line 59
def frozen?
thread_safe_access { settings.__is_frozen__ }
end
|
#key?(*key_path) ⇒ Boolean
Also known as:
option?, setting?
256
257
258
|
# File 'lib/qonfig/data_set.rb', line 256
def key?(*key_path)
thread_safe_access { settings.__has_key__(*key_path) }
end
|
#load_from_file(file_path, format: :dynamic, strict: true, expose: nil) ⇒ void
This method returns an undefined value.
88
89
90
91
92
|
# File 'lib/qonfig/data_set.rb', line 88
def load_from_file(file_path, format: :dynamic, strict: true, expose: nil)
thread_safe_access do
load_setting_values_from_file(file_path, format: format, strict: strict, expose: expose)
end
end
|
#load_from_json(file_path, strict: true, expose: nil) ⇒ void
This method returns an undefined value.
116
117
118
|
# File 'lib/qonfig/data_set.rb', line 116
def load_from_json(file_path, strict: true, expose: nil)
load_from_file(file_path, format: :json, strict: strict, expose: expose)
end
|
#load_from_self(format: :dynamic, strict: true, expose: nil) ⇒ void
This method returns an undefined value.
127
128
129
130
131
132
133
134
135
|
# File 'lib/qonfig/data_set.rb', line 127
def load_from_self(format: :dynamic, strict: true, expose: nil)
caller_location = caller(1, 1).first
thread_safe_access do
load_setting_values_from_file(
:self, format: format, strict: strict, expose: expose, caller_location: caller_location
)
end
end
|
#load_from_toml(file_path, strict: true, expose: nil) ⇒ void
This method returns an undefined value.
29
30
31
|
# File 'lib/qonfig/plugins/toml/data_set.rb', line 29
def load_from_toml(file_path, strict: true, expose: nil)
load_from_file(file_path, format: :toml, strict: strict, expose: expose)
end
|
#load_from_yaml(file_path, strict: true, expose: nil) ⇒ void
This method returns an undefined value.
103
104
105
|
# File 'lib/qonfig/data_set.rb', line 103
def load_from_yaml(file_path, strict: true, expose: nil)
load_from_file(file_path, format: :yml, strict: strict, expose: expose)
end
|
#reload!(settings_map = {}, &configurations) ⇒ void
This method returns an undefined value.
71
72
73
74
75
76
|
# File 'lib/qonfig/data_set.rb', line 71
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
|
#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.
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/qonfig/data_set.rb', line 189
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
229
230
231
|
# File 'lib/qonfig/data_set.rb', line 229
def slice(*keys)
thread_safe_access { settings.__slice__(*keys) }
end
|
#slice_value(*keys) ⇒ Hash, Any
238
239
240
|
# File 'lib/qonfig/data_set.rb', line 238
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.
247
248
249
|
# File 'lib/qonfig/data_set.rb', line 247
def subset(*keys)
thread_safe_access { settings.__subset__(*keys) }
end
|
#to_h(key_transformer: Qonfig::Settings::BASIC_SETTING_KEY_TRANSFORMER, value_transformer: Qonfig::Settings::BASIC_SETTING_VALUE_TRANSFORMER) ⇒ Hash
Also known as:
to_hash
#valid? ⇒ Boolean
300
301
302
|
# File 'lib/qonfig/data_set.rb', line 300
def valid?
thread_safe_access { validator.valid? }
end
|
#validate! ⇒ void
This method returns an undefined value.
308
309
310
|
# File 'lib/qonfig/data_set.rb', line 308
def validate!
thread_safe_access { validator.validate! }
end
|
#with(temporary_configurations = {}, &arbitary_code) ⇒ void
This method returns an undefined value.
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
# File 'lib/qonfig/data_set.rb', line 318
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
|