qonfig 0.22.0 → 0.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.rubocop.yml +19 -1
- data/.travis.yml +28 -20
- data/CHANGELOG.md +57 -1
- data/Gemfile.lock +102 -0
- data/LICENSE.txt +1 -1
- data/README.md +125 -9
- data/Rakefile +0 -1
- data/bin/rspec +1 -0
- data/gemfiles/with_external_deps.gemfile +2 -0
- data/gemfiles/with_external_deps.gemfile.lock +112 -0
- data/gemfiles/without_external_deps.gemfile.lock +102 -0
- data/lib/qonfig.rb +4 -1
- data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
- data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
- data/lib/qonfig/data_set.rb +5 -2
- data/lib/qonfig/dsl.rb +2 -2
- data/lib/qonfig/imports/direct_key.rb +8 -2
- data/lib/qonfig/imports/mappings.rb +8 -2
- data/lib/qonfig/loaders/basic.rb +2 -0
- data/lib/qonfig/loaders/json.rb +2 -1
- data/lib/qonfig/plugins.rb +1 -0
- data/lib/qonfig/plugins/pretty_print.rb +8 -1
- data/lib/qonfig/plugins/pretty_print/requirements.rb +3 -0
- data/lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb +44 -0
- data/lib/qonfig/plugins/toml/commands/definition/expose_toml.rb +4 -4
- data/lib/qonfig/plugins/toml/commands/definition/load_from_toml.rb +1 -1
- data/lib/qonfig/plugins/toml/data_set.rb +2 -2
- data/lib/qonfig/plugins/toml/dsl.rb +2 -2
- data/lib/qonfig/plugins/vault.rb +24 -0
- data/lib/qonfig/plugins/vault/commands/definition/expose_vault.rb +142 -0
- data/lib/qonfig/plugins/vault/commands/definition/load_from_vault.rb +53 -0
- data/lib/qonfig/plugins/vault/dsl.rb +35 -0
- data/lib/qonfig/plugins/vault/errors.rb +9 -0
- data/lib/qonfig/plugins/vault/loaders/vault.rb +73 -0
- data/lib/qonfig/settings.rb +83 -22
- data/lib/qonfig/settings/key_matcher.rb +3 -1
- data/lib/qonfig/uploaders/base.rb +2 -0
- data/lib/qonfig/uploaders/file.rb +2 -2
- data/lib/qonfig/uploaders/yaml.rb +3 -1
- data/lib/qonfig/version.rb +1 -1
- data/qonfig.gemspec +6 -9
- data/sig/.keep +0 -0
- data/spec/features/clear_options_spec.rb +92 -0
- data/spec/features/compacted_config_spec.rb +308 -0
- data/spec/features/composition_spec.rb +207 -0
- data/spec/features/config_definition_and_representation_spec.rb +535 -0
- data/spec/features/definition_order_spec.rb +69 -0
- data/spec/features/dig_functionality_spec.rb +47 -0
- data/spec/features/dot_notation_spec.rb +159 -0
- data/spec/features/export_settings_spec.rb +138 -0
- data/spec/features/expose_json_spec.rb +281 -0
- data/spec/features/expose_self/format_option_dynamic_spec.rb +69 -0
- data/spec/features/expose_self/format_option_json_spec.rb +74 -0
- data/spec/features/expose_self/format_option_unsupported_spec.rb +27 -0
- data/spec/features/expose_self/format_option_yaml_spec.rb +77 -0
- data/spec/features/expose_self_spec.rb +97 -0
- data/spec/features/expose_yaml_spec.rb +263 -0
- data/spec/features/freeze_state_spec.rb +122 -0
- data/spec/features/get_config_keys_spec.rb +62 -0
- data/spec/features/get_config_values_spec.rb +41 -0
- data/spec/features/has_a_key_spec.rb +48 -0
- data/spec/features/import_settings_spec.rb +323 -0
- data/spec/features/indifferent_access_spec.rb +57 -0
- data/spec/features/inheritance_spec.rb +110 -0
- data/spec/features/instantiation_without_class_definition_spec.rb +59 -0
- data/spec/features/iteration_over_setting_keys_spec.rb +48 -0
- data/spec/features/load_from_env_spec.rb +240 -0
- data/spec/features/load_from_json_spec.rb +97 -0
- data/spec/features/load_from_self/format_option_json_spec.rb +31 -0
- data/spec/features/load_from_self/format_option_unsupported_spec.rb +27 -0
- data/spec/features/load_from_self/format_option_yaml_spec.rb +49 -0
- data/spec/features/load_from_self/with_erb_instructions_spec.rb +33 -0
- data/spec/features/load_from_self/with_hash_like_data_representation_spec.rb +66 -0
- data/spec/features/load_from_self/with_non_hash_like_data_representation_spec.rb +19 -0
- data/spec/features/load_from_self/without_end_data_spec.rb +11 -0
- data/spec/features/load_from_yaml_spec.rb +110 -0
- data/spec/features/load_setting_values_from_file/by_instance_method_examples.rb +171 -0
- data/spec/features/load_setting_values_from_file/by_macros_examples.rb +165 -0
- data/spec/features/load_setting_values_from_file/load_from_json_spec.rb +21 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/end_data_with_env_spec.rb +100 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_end_data_spec.rb +129 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_incorrect_end_data_spec.rb +34 -0
- data/spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb +65 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/end_data_with_env_spec.rb +94 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_end_data_spec.rb +126 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_incorrect_end_data_spec.rb +32 -0
- data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/without_end_data_spec.rb +65 -0
- data/spec/features/load_setting_values_from_file/load_from_yaml_spec.rb +21 -0
- data/spec/features/load_setting_values_from_file/shared_behavior_spec.rb +33 -0
- data/spec/features/mixin_spec.rb +387 -0
- data/spec/features/non_redefineable_core_methods_spec.rb +29 -0
- data/spec/features/plugins/pretty_print_spec.rb +86 -0
- data/spec/features/plugins/toml/expose_self/format_option_toml_spec.rb +71 -0
- data/spec/features/plugins/toml/expose_toml_spec.rb +221 -0
- data/spec/features/plugins/toml/load_from_self/format_option_toml_spec.rb +27 -0
- data/spec/features/plugins/toml/load_from_toml_spec.rb +109 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_from_toml_spec.rb +27 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/end_data_with_env_spec.rb +95 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_end_data_spec.rb +125 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_incorrect_end_data_spec.rb +34 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/without_end_data_spec.rb +65 -0
- data/spec/features/plugins/toml/load_setting_values_from_file/shared_behavior_spec.rb +34 -0
- data/spec/features/plugins/toml/save_to_toml_spec.rb +149 -0
- data/spec/features/plugins/vault/expose_vault_spec.rb +117 -0
- data/spec/features/plugins/vault/load_from_vault_spec.rb +80 -0
- data/spec/features/plugins_spec.rb +89 -0
- data/spec/features/reload_spec.rb +75 -0
- data/spec/features/run_code_with_temporary_settings_spec.rb +104 -0
- data/spec/features/save_to_file/save_to_json_spec.rb +157 -0
- data/spec/features/save_to_file/save_to_yaml_spec.rb +189 -0
- data/spec/features/settings_as_predicates_spec.rb +47 -0
- data/spec/features/settings_redefinition_spec.rb +30 -0
- data/spec/features/slice_functionality_spec.rb +69 -0
- data/spec/features/subset_functionality_spec.rb +49 -0
- data/spec/features/validation_spec.rb +916 -0
- data/spec/fixtures/array_settings.yml +3 -0
- data/spec/fixtures/expose_json/incompatible_root_structure.json +6 -0
- data/spec/fixtures/expose_json/incompatible_structure.json +4 -0
- data/spec/fixtures/expose_json/project.development.json +7 -0
- data/spec/fixtures/expose_json/project.json +30 -0
- data/spec/fixtures/expose_json/project.production.json +7 -0
- data/spec/fixtures/expose_json/project.staging.json +7 -0
- data/spec/fixtures/expose_json/project.test.json +7 -0
- data/spec/fixtures/expose_yaml/incompatible_structure.yml +2 -0
- data/spec/fixtures/expose_yaml/project.development.yml +4 -0
- data/spec/fixtures/expose_yaml/project.production.yml +4 -0
- data/spec/fixtures/expose_yaml/project.staging.yml +4 -0
- data/spec/fixtures/expose_yaml/project.test.yml +4 -0
- data/spec/fixtures/expose_yaml/project.yml +25 -0
- data/spec/fixtures/json_array_sample.json +14 -0
- data/spec/fixtures/json_object_sample.json +9 -0
- data/spec/fixtures/json_with_empty_object.json +6 -0
- data/spec/fixtures/json_with_erb.json +6 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.development.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.production.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.staging.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.test.toml +4 -0
- data/spec/fixtures/plugins/toml/expose_toml/project.toml +27 -0
- data/spec/fixtures/plugins/toml/mini_file.toml +6 -0
- data/spec/fixtures/plugins/toml/toml_sample_with_all_types.toml +72 -0
- data/spec/fixtures/plugins/toml/values_file/with_env.toml +13 -0
- data/spec/fixtures/plugins/toml/values_file/without_env.toml +6 -0
- data/spec/fixtures/rubocop_settings.yml +12 -0
- data/spec/fixtures/shared_settings_with_aliases.yml +10 -0
- data/spec/fixtures/travis_settings.yml +6 -0
- data/spec/fixtures/values_file/with_env.json +19 -0
- data/spec/fixtures/values_file/with_env.yml +17 -0
- data/spec/fixtures/values_file/without_env.json +8 -0
- data/spec/fixtures/values_file/without_env.yml +5 -0
- data/spec/fixtures/with_empty_hash.yml +4 -0
- data/spec/fixtures/with_erb_instructions.yml +3 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/meta_scopes.rb +20 -0
- data/spec/support/spec_support.rb +42 -0
- metadata +140 -30
data/lib/qonfig/settings.rb
CHANGED
@@ -22,6 +22,12 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
22
22
|
# @since 0.11.0
|
23
23
|
BASIC_SETTING_VALUE_TRANSFORMER = (proc { |value| value }).freeze
|
24
24
|
|
25
|
+
# @return [Boolean]
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
# @since 0.25.0
|
29
|
+
REPRESENT_HASH_IN_DOT_STYLE = false
|
30
|
+
|
25
31
|
# @return [String]
|
26
32
|
#
|
27
33
|
# @api private
|
@@ -94,6 +100,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
94
100
|
|
95
101
|
__prevent_core_method_intersection__(key)
|
96
102
|
|
103
|
+
# rubocop:disable Lint/DuplicateBranch
|
97
104
|
case
|
98
105
|
when with_redefinition || !__options__.key?(key)
|
99
106
|
__options__[key] = value
|
@@ -102,6 +109,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
102
109
|
else
|
103
110
|
__options__[key] = value
|
104
111
|
end
|
112
|
+
# rubocop:enable Lint/DuplicateBranch
|
105
113
|
|
106
114
|
__define_option_reader__(key)
|
107
115
|
__define_option_writer__(key)
|
@@ -133,16 +141,13 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
133
141
|
# @param key [Symbol, String]
|
134
142
|
# @return [Object]
|
135
143
|
#
|
144
|
+
# @raise [Qonfig::ArgumentError]
|
145
|
+
#
|
136
146
|
# @api public
|
137
147
|
# @since 0.1.0
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
__get_value__(key)
|
142
|
-
rescue Qonfig::UnknownSettingError
|
143
|
-
__deep_access__(*__parse_dot_notated_key__(key))
|
144
|
-
end
|
145
|
-
end
|
148
|
+
# @version 0.25.0
|
149
|
+
def [](*keys)
|
150
|
+
__dig__(*keys)
|
146
151
|
end
|
147
152
|
|
148
153
|
# @param key [String, Symbol]
|
@@ -211,27 +216,47 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
211
216
|
__lock__.thread_safe_access { __deep_subset__(*keys) }
|
212
217
|
end
|
213
218
|
|
219
|
+
# @option dot_notation [Boolean]
|
214
220
|
# @option transform_key [Proc]
|
215
221
|
# @option transform_value [Proc]
|
216
222
|
# @return [Hash]
|
217
223
|
#
|
218
224
|
# @api private
|
219
225
|
# @since 0.1.0
|
220
|
-
#
|
221
|
-
def __to_hash__(
|
226
|
+
# @version 0.25.0
|
227
|
+
def __to_hash__(
|
228
|
+
dot_notation: REPRESENT_HASH_IN_DOT_STYLE,
|
229
|
+
transform_key: BASIC_SETTING_KEY_TRANSFORMER,
|
230
|
+
transform_value: BASIC_SETTING_VALUE_TRANSFORMER
|
231
|
+
)
|
222
232
|
unless transform_key.is_a?(Proc)
|
223
|
-
::Kernel.raise(
|
233
|
+
::Kernel.raise(
|
234
|
+
Qonfig::IncorrectKeyTransformerError,
|
235
|
+
'Key transformer should be a type of proc'
|
236
|
+
)
|
224
237
|
end
|
225
238
|
|
226
239
|
unless transform_value.is_a?(Proc)
|
227
|
-
::Kernel.raise(
|
240
|
+
::Kernel.raise(
|
241
|
+
Qonfig::IncorrectValueTransformerError,
|
242
|
+
'Value transformer should be a type of proc'
|
243
|
+
)
|
228
244
|
end
|
229
245
|
|
230
246
|
__lock__.thread_safe_access do
|
231
|
-
|
247
|
+
if dot_notation
|
248
|
+
__build_dot_notated_hash_representation__(
|
249
|
+
transform_key: transform_key,
|
250
|
+
transform_value: transform_value
|
251
|
+
)
|
252
|
+
else
|
253
|
+
__build_basic_hash_representation__(
|
254
|
+
transform_key: transform_key,
|
255
|
+
transform_value: transform_value
|
256
|
+
)
|
257
|
+
end
|
232
258
|
end
|
233
259
|
end
|
234
|
-
# rubocop:enable Metrics/LineLength
|
235
260
|
alias_method :__to_h__, :__to_hash__
|
236
261
|
|
237
262
|
# @option all_variants [Boolean]
|
@@ -496,7 +521,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
496
521
|
#
|
497
522
|
# @api private
|
498
523
|
# @since 0.21.0
|
499
|
-
# rubocop:disable Naming/RescuedExceptionsVariableName
|
524
|
+
# rubocop:disable Naming/RescuedExceptionsVariableName, Style/SlicingWithRange
|
500
525
|
def __assign_value__(key, value)
|
501
526
|
key = __indifferently_accessable_option_key__(key)
|
502
527
|
__set_value__(key, value)
|
@@ -507,6 +532,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
507
532
|
raise(initial_error) if key_set.size == 1
|
508
533
|
|
509
534
|
begin
|
535
|
+
# TODO: rewrite with __deep_access__-like key resolving functionality
|
510
536
|
setting_value = __get_value__(key_set.first)
|
511
537
|
required_key = key_set[1..-1].join(DOT_NOTATION_SEPARATOR)
|
512
538
|
setting_value[required_key] = value # NOTE: pseudo-recoursive assignment
|
@@ -514,7 +540,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
514
540
|
raise(initial_error)
|
515
541
|
end
|
516
542
|
end
|
517
|
-
# rubocop:enable Naming/RescuedExceptionsVariableName
|
543
|
+
# rubocop:enable Naming/RescuedExceptionsVariableName, Style/SlicingWithRange
|
518
544
|
|
519
545
|
# @param key [String, Symbol]
|
520
546
|
# @param value [Object]
|
@@ -557,11 +583,24 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
557
583
|
#
|
558
584
|
# @api private
|
559
585
|
# @since 0.2.0
|
586
|
+
# rubocop:disable Metrics/AbcSize, Style/SlicingWithRange
|
560
587
|
def __deep_access__(*keys)
|
561
588
|
::Kernel.raise(Qonfig::ArgumentError, 'Key list can not be empty') if keys.empty?
|
562
589
|
|
563
|
-
result =
|
564
|
-
rest_keys =
|
590
|
+
result = nil
|
591
|
+
rest_keys = nil
|
592
|
+
key_parts_boundary = keys.size - 1
|
593
|
+
|
594
|
+
0.upto(key_parts_boundary) do |key_parts_slice_boundary|
|
595
|
+
begin
|
596
|
+
setting_key = keys[0..key_parts_slice_boundary].join(DOT_NOTATION_SEPARATOR)
|
597
|
+
result = __get_value__(setting_key)
|
598
|
+
rest_keys = Array(keys[(key_parts_slice_boundary + 1)..-1])
|
599
|
+
break
|
600
|
+
rescue Qonfig::UnknownSettingError => error
|
601
|
+
key_parts_boundary == key_parts_slice_boundary ? raise(error) : next
|
602
|
+
end
|
603
|
+
end
|
565
604
|
|
566
605
|
case
|
567
606
|
when rest_keys.empty?
|
@@ -575,6 +614,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
575
614
|
result.__dig__(*rest_keys)
|
576
615
|
end
|
577
616
|
end
|
617
|
+
# rubocop:enable Metrics/AbcSize, Style/SlicingWithRange
|
578
618
|
|
579
619
|
# @param keys [Array<Symbol, String>]
|
580
620
|
# @return [Hash]
|
@@ -584,6 +624,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
584
624
|
#
|
585
625
|
# @api private
|
586
626
|
# @since 0.9.0
|
627
|
+
# rubocop:disable Metrics/AbcSize
|
587
628
|
def __deep_slice__(*keys)
|
588
629
|
{}.tap do |result|
|
589
630
|
begin
|
@@ -604,6 +645,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
604
645
|
end
|
605
646
|
end
|
606
647
|
end
|
648
|
+
# rubocop:enable Metrics/AbcSize
|
607
649
|
|
608
650
|
# @param keys [Array<Symbol, String>]
|
609
651
|
# @return [Hash]
|
@@ -647,7 +689,7 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
647
689
|
# TODO: support for patterns
|
648
690
|
__indifferently_accessable_option_key__(key_set)
|
649
691
|
when Array
|
650
|
-
key_set.map(
|
692
|
+
key_set.map { |key| __indifferently_accessable_option_key__(key) }
|
651
693
|
else
|
652
694
|
raise(
|
653
695
|
Qonfig::ArgumentError,
|
@@ -667,14 +709,15 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
667
709
|
# @return [Hash]
|
668
710
|
#
|
669
711
|
# @api private
|
670
|
-
# @since 0.
|
671
|
-
|
712
|
+
# @since 0.25.0
|
713
|
+
# rubocop:disable Layout/LineLength
|
714
|
+
def __build_basic_hash_representation__(options_part = __options__, transform_key:, transform_value:)
|
672
715
|
options_part.each_with_object({}) do |(key, value), hash|
|
673
716
|
final_key = transform_key.call(key)
|
674
717
|
|
675
718
|
case
|
676
719
|
when value.is_a?(Hash)
|
677
|
-
hash[final_key] =
|
720
|
+
hash[final_key] = __build_basic_hash_representation__(
|
678
721
|
value,
|
679
722
|
transform_key: transform_key,
|
680
723
|
transform_value: transform_value
|
@@ -690,6 +733,24 @@ class Qonfig::Settings # NOTE: Layout/ClassStructure is disabled only for CORE_M
|
|
690
733
|
end
|
691
734
|
end
|
692
735
|
end
|
736
|
+
# rubocop:enable Layout/LineLength
|
737
|
+
|
738
|
+
# @option transform_key [Proc]
|
739
|
+
# @option transform_value [Proc]
|
740
|
+
# @return [Hash]
|
741
|
+
#
|
742
|
+
# @api private
|
743
|
+
# @since 0.25.0
|
744
|
+
def __build_dot_notated_hash_representation__(transform_key:, transform_value:)
|
745
|
+
{}.tap do |hash|
|
746
|
+
__deep_each_key_value_pair__ do |setting_key, setting_value|
|
747
|
+
final_key = transform_key.call(setting_key)
|
748
|
+
final_value = transform_value.call(setting_value)
|
749
|
+
|
750
|
+
hash[final_key] = final_value
|
751
|
+
end
|
752
|
+
end
|
753
|
+
end
|
693
754
|
|
694
755
|
# @param key [Symbol, String]
|
695
756
|
# @return [void]
|
@@ -147,12 +147,14 @@ class Qonfig::Settings::KeyMatcher
|
|
147
147
|
#
|
148
148
|
# @api private
|
149
149
|
# @since 0.13.0
|
150
|
+
# rubocop:disable Style/SlicingWithRange
|
150
151
|
def strip_regexp_string(regexp_string, left: false, right: false)
|
151
152
|
pattern = regexp_string
|
152
153
|
pattern = pattern[2..-1] if left && pattern[0..1] == MATCHER_SCOPE_SPLITTER
|
153
154
|
pattern = pattern[0..-3] if right && pattern[-2..-1] == MATCHER_SCOPE_SPLITTER
|
154
155
|
pattern
|
155
156
|
end
|
157
|
+
# rubocop:enable Style/SlicingWithRange
|
156
158
|
|
157
159
|
# @param scope_pattern [String]
|
158
160
|
# @return [Regexp]
|
@@ -179,6 +181,6 @@ class Qonfig::Settings::KeyMatcher
|
|
179
181
|
|
180
182
|
regexp_string = strip_regexp_string(regexp_string, left: true, right: true)
|
181
183
|
|
182
|
-
Regexp.new(
|
184
|
+
Regexp.new("\\A#{regexp_string}\\z")
|
183
185
|
end
|
184
186
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# @api private
|
4
4
|
# @since 0.11.0
|
5
|
+
# rubocop:disable Style/StaticClass
|
5
6
|
class Qonfig::Uploaders::Base
|
6
7
|
class << self
|
7
8
|
# @param settings [Qonfig::Settings]
|
@@ -16,3 +17,4 @@ class Qonfig::Uploaders::Base
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
20
|
+
# rubocop:enable Style/StaticClass
|
@@ -23,9 +23,9 @@ class Qonfig::Uploaders::File < Qonfig::Uploaders::Base
|
|
23
23
|
|
24
24
|
class << self
|
25
25
|
# @param settings [Qonfig::Settings]
|
26
|
-
# @param options [Hash<Symbol|String,Any>]
|
27
26
|
# @param value_processor [Block]
|
28
|
-
# @option path [String]
|
27
|
+
# @option path [String, Pathname]
|
28
|
+
# @option options [Hash<Symbol|String,Any>]
|
29
29
|
# @return [void]
|
30
30
|
#
|
31
31
|
# @api private
|
@@ -47,7 +47,7 @@ class Qonfig::Uploaders::YAML < Qonfig::Uploaders::File
|
|
47
47
|
# @since 0.11.0
|
48
48
|
def represent_settings(settings, options, &value_processor)
|
49
49
|
settings_hash_opts = hash_representation_options(options, &value_processor)
|
50
|
-
settings_hash = settings.__to_hash__(settings_hash_opts)
|
50
|
+
settings_hash = settings.__to_hash__(**settings_hash_opts)
|
51
51
|
to_yaml_string(settings_hash, options)
|
52
52
|
end
|
53
53
|
|
@@ -60,6 +60,7 @@ class Qonfig::Uploaders::YAML < Qonfig::Uploaders::File
|
|
60
60
|
def hash_representation_options(options, &value_processor)
|
61
61
|
{}.tap do |representation_opts|
|
62
62
|
# NOTE: this case/when with the same logic is only used for better code readbility
|
63
|
+
# rubocop:disable Lint/DuplicateBranch
|
63
64
|
case
|
64
65
|
# NOTE: options has :symbolize_keys key
|
65
66
|
when options.key?(:symbolize_keys) && !!options[:symbolize_keys]
|
@@ -70,6 +71,7 @@ class Qonfig::Uploaders::YAML < Qonfig::Uploaders::File
|
|
70
71
|
representation_opts[:transform_key] = KEY_SYMBOLIZER
|
71
72
|
# :nocov:
|
72
73
|
end
|
74
|
+
# rubocop:enable Lint/DuplicateBranch
|
73
75
|
|
74
76
|
# NOTE: provide value transformer
|
75
77
|
if block_given?
|
data/lib/qonfig/version.rb
CHANGED
data/qonfig.gemspec
CHANGED
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
6
|
require 'qonfig/version'
|
7
7
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
|
-
spec.required_ruby_version = '>= 2.4.
|
9
|
+
spec.required_ruby_version = '>= 2.4.10'
|
10
10
|
|
11
11
|
spec.name = 'qonfig'
|
12
12
|
spec.version = Qonfig::VERSION
|
@@ -25,16 +25,13 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ['lib']
|
27
27
|
|
28
|
-
spec.files = `git ls-files -z`.split("\x0")
|
29
|
-
f.match(%r{^(test|spec|features)/})
|
30
|
-
end
|
28
|
+
spec.files = `git ls-files -z`.split("\x0")
|
31
29
|
|
32
|
-
spec.add_development_dependency '
|
33
|
-
spec.add_development_dependency '
|
34
|
-
spec.add_development_dependency '
|
35
|
-
spec.add_development_dependency 'armitage-rubocop', '~> 0.77'
|
30
|
+
spec.add_development_dependency 'simplecov', '~> 0.20'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.10'
|
32
|
+
spec.add_development_dependency 'armitage-rubocop', '~> 1.7'
|
36
33
|
|
37
34
|
spec.add_development_dependency 'bundler'
|
38
|
-
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rake', '>= 13'
|
39
36
|
spec.add_development_dependency 'pry'
|
40
37
|
end
|
data/sig/.keep
ADDED
File without changes
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Clear options' do
|
4
|
+
specify '#clear - sets all options to nil' do
|
5
|
+
ENV['QONFIG_CLEAR_GENERIC_OPTION'] = 'true'
|
6
|
+
ENV['QONFIG_CLEAR_MEGA_SECRET_VALUE'] = '100500'
|
7
|
+
|
8
|
+
class SimplifiedConfig < Qonfig::DataSet
|
9
|
+
setting :a do
|
10
|
+
setting :b do
|
11
|
+
setting :c, 55
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
load_from_env prefix: 'QONFIG_CLEAR'
|
16
|
+
end
|
17
|
+
|
18
|
+
class CleansedConfig < Qonfig::DataSet
|
19
|
+
setting :database do
|
20
|
+
setting :user, '0exp'
|
21
|
+
setting :password, 'test123'
|
22
|
+
end
|
23
|
+
|
24
|
+
setting :travis do
|
25
|
+
load_from_yaml SpecSupport.fixture_path('travis_settings.yml')
|
26
|
+
end
|
27
|
+
|
28
|
+
setting :self_data do
|
29
|
+
load_from_self
|
30
|
+
end
|
31
|
+
|
32
|
+
setting :env_data do
|
33
|
+
load_from_env convert_values: true, prefix: /\AQONFIG_CLEAR.*\z/i
|
34
|
+
end
|
35
|
+
|
36
|
+
setting :composed do
|
37
|
+
compose SimplifiedConfig
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
config = CleansedConfig.new
|
42
|
+
|
43
|
+
config.clear!
|
44
|
+
|
45
|
+
expect(config[:database][:user]).to eq(nil)
|
46
|
+
expect(config[:database][:password]).to eq(nil)
|
47
|
+
expect(config[:travis][:sudo]).to eq(nil)
|
48
|
+
expect(config[:travis][:language]).to eq(nil)
|
49
|
+
expect(config[:travis][:rvm]).to eq(nil)
|
50
|
+
expect(config[:self_data][:secret_key]).to eq(nil)
|
51
|
+
expect(config[:self_data][:api_host]).to eq(nil)
|
52
|
+
expect(config[:self_data][:connection_timeout][:seconds]).to eq(nil)
|
53
|
+
expect(config[:self_data][:connection_timeout][:enabled]).to eq(nil)
|
54
|
+
expect(config[:env_data][:QONFIG_CLEAR_GENERIC_OPTION]).to eq(nil)
|
55
|
+
expect(config[:env_data][:QONFIG_CLEAR_MEGA_SECRET_VALUE]).to eq(nil)
|
56
|
+
expect(config[:composed][:a][:b][:c]).to eq(nil)
|
57
|
+
|
58
|
+
expect(config.to_h).to match(
|
59
|
+
'database' => { 'user' => nil, 'password' => nil },
|
60
|
+
'travis' => {
|
61
|
+
'sudo' => nil,
|
62
|
+
'language' => nil,
|
63
|
+
'rvm' => nil
|
64
|
+
},
|
65
|
+
'self_data' => {
|
66
|
+
'secret_key' => nil,
|
67
|
+
'api_host' => nil,
|
68
|
+
'connection_timeout' => {
|
69
|
+
'seconds' => nil,
|
70
|
+
'enabled' => nil
|
71
|
+
}
|
72
|
+
},
|
73
|
+
'env_data' => {
|
74
|
+
'QONFIG_CLEAR_GENERIC_OPTION' => nil,
|
75
|
+
'QONFIG_CLEAR_MEGA_SECRET_VALUE' => nil
|
76
|
+
},
|
77
|
+
'composed' => {
|
78
|
+
'a' => { 'b' => { 'c' => nil } },
|
79
|
+
'QONFIG_CLEAR_GENERIC_OPTION' => nil,
|
80
|
+
'QONFIG_CLEAR_MEGA_SECRET_VALUE' => nil
|
81
|
+
}
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
__END__
|
87
|
+
|
88
|
+
secret_key: top-mega-secret
|
89
|
+
api_host: super.puper-google.com
|
90
|
+
:connection_timeout:
|
91
|
+
seconds: 10
|
92
|
+
enabled: false
|
@@ -0,0 +1,308 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Compacted config' do
|
4
|
+
describe 'definition and settings access' do
|
5
|
+
specify 'constructor without dataset builds compacted config from config\'s class commands' do
|
6
|
+
class CompactedCommandsCheck < Qonfig::Compacted
|
7
|
+
setting :test, true
|
8
|
+
setting :db do
|
9
|
+
setting :creds do
|
10
|
+
setting :user, '0exp'
|
11
|
+
setting :password, 'test123'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
validate :test, :boolean
|
16
|
+
validate 'db.creds.*', :string
|
17
|
+
end
|
18
|
+
|
19
|
+
compacted_config = CompactedCommandsCheck.new
|
20
|
+
|
21
|
+
# NOTE: check readers
|
22
|
+
expect(compacted_config.test).to eq(true)
|
23
|
+
expect(compacted_config.db.creds.user).to eq('0exp')
|
24
|
+
expect(compacted_config.db.creds.password).to eq('test123')
|
25
|
+
# and dot-notation:
|
26
|
+
expect(compacted_config[:test]).to eq(true)
|
27
|
+
expect(compacted_config['db.creds.user']).to eq('0exp')
|
28
|
+
expect(compacted_config['db.creds.password']).to eq('test123')
|
29
|
+
|
30
|
+
# NOTE: check writers
|
31
|
+
compacted_config.test = false
|
32
|
+
compacted_config.db.creds.user = 'D@iVeR'
|
33
|
+
# and dot-notation:
|
34
|
+
compacted_config['db.creds.password'] = 'atata123'
|
35
|
+
|
36
|
+
# NOTE: check new values
|
37
|
+
expect(compacted_config.test).to eq(false)
|
38
|
+
expect(compacted_config.db.creds.user).to eq('D@iVeR')
|
39
|
+
expect(compacted_config.db.creds.password).to eq('atata123')
|
40
|
+
|
41
|
+
# NOTE: check validators
|
42
|
+
expect { compacted_config.test = 123 }.to raise_error(Qonfig::ValidationError)
|
43
|
+
expect { compacted_config.db.creds.user = 123 }.to raise_error(Qonfig::ValidationError)
|
44
|
+
expect { compacted_config['db.creds.password'] = 123 }.to raise_error(Qonfig::ValidationError)
|
45
|
+
end
|
46
|
+
|
47
|
+
specify 'support for predicates' do
|
48
|
+
class PredicateCheckForCompactedConfig < Qonfig::Compacted
|
49
|
+
setting :enabled, true
|
50
|
+
setting :queue do
|
51
|
+
setting :engine, nil
|
52
|
+
setting :workers_count, 10
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
config = PredicateCheckForCompactedConfig.new
|
57
|
+
|
58
|
+
expect(config.enabled?).to eq(true)
|
59
|
+
expect(config.queue?).to eq(true)
|
60
|
+
expect(config.queue.engine?).to eq(false)
|
61
|
+
expect(config.queue.workers_count?).to eq(true)
|
62
|
+
|
63
|
+
config.enabled = nil
|
64
|
+
config.queue.engine = :sidekiq
|
65
|
+
|
66
|
+
expect(config.enabled?).to eq(false)
|
67
|
+
expect(config.queue.engine?).to eq(true)
|
68
|
+
|
69
|
+
config.enabled = false
|
70
|
+
expect(config.enabled?).to eq(false)
|
71
|
+
end
|
72
|
+
|
73
|
+
specify 'constructor with passed dataset builds compacted config from passed dataset' do
|
74
|
+
data_set_based_config = Class.new(Qonfig::DataSet).build do
|
75
|
+
setting :test, true
|
76
|
+
setting :db do
|
77
|
+
setting :creds do
|
78
|
+
setting :user, '0exp'
|
79
|
+
setting :password, 'test123'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
validate :test, :boolean
|
84
|
+
validate 'db.creds.*', :string
|
85
|
+
end
|
86
|
+
|
87
|
+
compacted_config = Qonfig::Compacted.build_from(data_set_based_config)
|
88
|
+
|
89
|
+
# NOTE: check readers
|
90
|
+
expect(compacted_config.test).to eq(true)
|
91
|
+
expect(compacted_config.db.creds.user).to eq('0exp')
|
92
|
+
expect(compacted_config.db.creds.password).to eq('test123')
|
93
|
+
# and dot-notation:
|
94
|
+
expect(compacted_config[:test]).to eq(true)
|
95
|
+
expect(compacted_config['db.creds.user']).to eq('0exp')
|
96
|
+
expect(compacted_config['db.creds.password']).to eq('test123')
|
97
|
+
|
98
|
+
# NOTE: check writers
|
99
|
+
compacted_config.test = false
|
100
|
+
compacted_config.db.creds.user = 'D@iVeR'
|
101
|
+
# and dot-notation:
|
102
|
+
compacted_config['db.creds.password'] = 'atata123'
|
103
|
+
|
104
|
+
# NOTE: check new values
|
105
|
+
expect(compacted_config.test).to eq(false)
|
106
|
+
expect(compacted_config.db.creds.user).to eq('D@iVeR')
|
107
|
+
expect(compacted_config.db.creds.password).to eq('atata123')
|
108
|
+
|
109
|
+
# NOTE: check validators
|
110
|
+
expect { compacted_config.test = 123 }.to raise_error(Qonfig::ValidationError)
|
111
|
+
expect { compacted_config.db.creds.user = 123 }.to raise_error(Qonfig::ValidationError)
|
112
|
+
expect { compacted_config['db.creds.password'] = 123 }.to raise_error(Qonfig::ValidationError)
|
113
|
+
end
|
114
|
+
|
115
|
+
specify 'fails on incorrect datasets passed to constructor' do
|
116
|
+
expect { Qonfig::Compacted.build_from(Object.new) }.to raise_error(Qonfig::ArgumentError)
|
117
|
+
end
|
118
|
+
|
119
|
+
specify 'inheritance works as expected' do
|
120
|
+
class BaseCompactedConfig < Qonfig::Compacted
|
121
|
+
setting :test, true
|
122
|
+
setting :db do
|
123
|
+
setting :creds do
|
124
|
+
setting :user, '0exp'
|
125
|
+
setting :password, 'test123'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
validate :test, :boolean
|
130
|
+
validate 'db.creds.*', :string
|
131
|
+
end
|
132
|
+
|
133
|
+
class ChildCompactedConfig < BaseCompactedConfig
|
134
|
+
setting :db do
|
135
|
+
setting :creds do
|
136
|
+
setting :token, 'kekpek'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
child_compacted_config = ChildCompactedConfig.new
|
142
|
+
|
143
|
+
# NOTE: check readers
|
144
|
+
expect(child_compacted_config.test).to eq(true)
|
145
|
+
expect(child_compacted_config.db.creds.user).to eq('0exp')
|
146
|
+
expect(child_compacted_config.db.creds.password).to eq('test123')
|
147
|
+
expect(child_compacted_config.db.creds.token).to eq('kekpek')
|
148
|
+
# and dot-notation:
|
149
|
+
expect(child_compacted_config[:test]).to eq(true)
|
150
|
+
expect(child_compacted_config['db.creds.user']).to eq('0exp')
|
151
|
+
expect(child_compacted_config['db.creds.password']).to eq('test123')
|
152
|
+
expect(child_compacted_config['db.creds.token']).to eq('kekpek')
|
153
|
+
|
154
|
+
# NOTE: check writers
|
155
|
+
child_compacted_config.test = false
|
156
|
+
child_compacted_config.db.creds.user = 'D@iVeR'
|
157
|
+
child_compacted_config.db.creds.password = 'atata123'
|
158
|
+
child_compacted_config.db.creds.token = 'trututu'
|
159
|
+
|
160
|
+
# NOTE: check new values
|
161
|
+
expect(child_compacted_config.test).to eq(false)
|
162
|
+
expect(child_compacted_config.db.creds.user).to eq('D@iVeR')
|
163
|
+
expect(child_compacted_config.db.creds.password).to eq('atata123')
|
164
|
+
expect(child_compacted_config.db.creds.token).to eq('trututu')
|
165
|
+
|
166
|
+
# NOTE: check validators
|
167
|
+
# rubocop:disable Layout/LineLength
|
168
|
+
expect { child_compacted_config.test = 123 }.to raise_error(Qonfig::ValidationError)
|
169
|
+
expect { child_compacted_config.db.creds.user = 123 }.to raise_error(Qonfig::ValidationError)
|
170
|
+
expect { child_compacted_config['db.creds.password'] = 123 }.to raise_error(Qonfig::ValidationError)
|
171
|
+
expect { child_compacted_config.db.creds.token = 123 }.to raise_error(Qonfig::ValidationError)
|
172
|
+
# rubocop:enable Layout/LineLength
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'instantiation without definition' do
|
176
|
+
specify 'creates new Qonfig::Compacted instance' do
|
177
|
+
config = Qonfig::Compacted.build do
|
178
|
+
setting :api, 'api.overwatch.com'
|
179
|
+
setting(:tokens) { setting :internal, 'test123' }
|
180
|
+
end
|
181
|
+
|
182
|
+
expect((class << config; self; end).superclass.superclass).to eq(Qonfig::Compacted)
|
183
|
+
expect(config.api).to eq('api.overwatch.com')
|
184
|
+
expect(config.tokens.internal).to eq('test123')
|
185
|
+
end
|
186
|
+
|
187
|
+
specify 'can inherit existing Qonfig::Compacted class' do
|
188
|
+
base_config_klass = Class.new(Qonfig::Compacted) do
|
189
|
+
setting(:creds) { setting :login, 'test123' }
|
190
|
+
setting :enabled, true
|
191
|
+
end
|
192
|
+
|
193
|
+
config = Qonfig::Compacted.build(base_config_klass) do
|
194
|
+
setting :api, 'api.overwatch.com'
|
195
|
+
setting :enabled, false
|
196
|
+
setting(:creds) { setting :password, 'kekpek' }
|
197
|
+
end
|
198
|
+
|
199
|
+
expect(config.creds.login).to eq('test123') # NOTE: inherited definition
|
200
|
+
expect(config.enabled).to eq(false) # NOTE: redefined setting
|
201
|
+
expect(config.creds.password).to eq('kekpek') # NOTE: extended setting "creds"
|
202
|
+
expect(config.api).to eq('api.overwatch.com') # NOTE: own setting
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
specify 'Qonfig::DataSet#compacted build compacted config from itself' do
|
207
|
+
class CompactCheckConfig < Qonfig::DataSet
|
208
|
+
setting :db do
|
209
|
+
setting :creds do
|
210
|
+
setting :user, 'D@iVeR'
|
211
|
+
setting :password, 'test123'
|
212
|
+
setting :data, test: false
|
213
|
+
end
|
214
|
+
end
|
215
|
+
setting :logger, nil
|
216
|
+
setting :graphql_endpoint, 'https://localhost:1234/graphql'
|
217
|
+
end
|
218
|
+
|
219
|
+
compacted_config = CompactCheckConfig.new.compacted
|
220
|
+
|
221
|
+
# NOTE: check readers
|
222
|
+
expect(compacted_config.db.creds.user).to eq('D@iVeR')
|
223
|
+
expect(compacted_config.db.creds.password).to eq('test123')
|
224
|
+
expect(compacted_config.db.creds.data).to eq(test: false)
|
225
|
+
expect(compacted_config.logger).to eq(nil)
|
226
|
+
expect(compacted_config.graphql_endpoint).to eq('https://localhost:1234/graphql')
|
227
|
+
|
228
|
+
# NOTE: check writers
|
229
|
+
# ambigous write is impossible
|
230
|
+
expect do
|
231
|
+
compacted_config.db = :test
|
232
|
+
end.to raise_error(Qonfig::AmbiguousSettingValueError)
|
233
|
+
expect do
|
234
|
+
compacted_config.db.creds = :test
|
235
|
+
end.to raise_error(Qonfig::AmbiguousSettingValueError)
|
236
|
+
# regular write is possible :)
|
237
|
+
compacted_config.db.creds.user = '0exp'
|
238
|
+
compacted_config.db.creds.password = '123test'
|
239
|
+
compacted_config.db.creds.data = { no: :errors }
|
240
|
+
compacted_config.logger = :logger
|
241
|
+
compacted_config.graphql_endpoint = 'https://localhost:4321/graphql'
|
242
|
+
# corresponding values was correctly assigned
|
243
|
+
expect(compacted_config.db.creds.user).to eq('0exp')
|
244
|
+
expect(compacted_config.db.creds.password).to eq('123test')
|
245
|
+
expect(compacted_config.db.creds.data).to eq(no: :errors)
|
246
|
+
expect(compacted_config.logger).to eq(:logger)
|
247
|
+
expect(compacted_config.graphql_endpoint).to eq('https://localhost:4321/graphql')
|
248
|
+
end
|
249
|
+
|
250
|
+
specify 'Qonfig::DataSet.build_compacted - builds compacted config object' do
|
251
|
+
compacted_config = Qonfig::DataSet.build_compacted do
|
252
|
+
setting(:db) { setting(:creds) { setting :user, '0exp' } }
|
253
|
+
setting :logger, :no_logger
|
254
|
+
setting :graphql_endpoint, '/graph_dracula'
|
255
|
+
end
|
256
|
+
|
257
|
+
# NOTE: check readers
|
258
|
+
expect(compacted_config.db.creds.user).to eq('0exp')
|
259
|
+
expect(compacted_config.logger).to eq(:no_logger)
|
260
|
+
expect(compacted_config.graphql_endpoint).to eq('/graph_dracula')
|
261
|
+
|
262
|
+
# NOTE: check writers
|
263
|
+
# ambigous write is impossible
|
264
|
+
expect do
|
265
|
+
compacted_config.db = :test
|
266
|
+
end.to raise_error(Qonfig::AmbiguousSettingValueError)
|
267
|
+
expect do
|
268
|
+
compacted_config.db.creds = :test
|
269
|
+
end.to raise_error(Qonfig::AmbiguousSettingValueError)
|
270
|
+
# regular write is possible :)
|
271
|
+
compacted_config.db.creds.user = 'D@iVeR'
|
272
|
+
compacted_config.logger = :logger
|
273
|
+
compacted_config.graphql_endpoint = 'https://localhost:4321/graphql'
|
274
|
+
# corresponding values was correctly assigned
|
275
|
+
expect(compacted_config.db.creds.user).to eq('D@iVeR')
|
276
|
+
expect(compacted_config.logger).to eq(:logger)
|
277
|
+
expect(compacted_config.graphql_endpoint).to eq('https://localhost:4321/graphql')
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe '(.valid_with?) class-level pre-validation checking' do
|
282
|
+
specify 'support for do-config notation :)' do
|
283
|
+
config_klass = Class.new(Qonfig::Compacted) do
|
284
|
+
setting :enabled, false
|
285
|
+
setting(:db) { setting :user, 'D@iVeR' }
|
286
|
+
validate :enabled, :boolean, strict: true
|
287
|
+
validate 'db.#', :text, strict: true
|
288
|
+
end
|
289
|
+
|
290
|
+
# class-level checker
|
291
|
+
expect(
|
292
|
+
(config_klass.valid_with?(enabled: true) do |conf|
|
293
|
+
conf.db.user = '0exp'
|
294
|
+
end)
|
295
|
+
).to eq(true)
|
296
|
+
expect(
|
297
|
+
(config_klass.valid_with?(enabled: false) do |conf|
|
298
|
+
conf.db.user = 123
|
299
|
+
end)
|
300
|
+
).to eq(false)
|
301
|
+
expect(
|
302
|
+
(config_klass.valid_with?(enabled: nil) do |conf|
|
303
|
+
conf.db.user = 'test'
|
304
|
+
end)
|
305
|
+
).to eq(false)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
end
|