qonfig 0.24.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +62 -0
  3. data/.gitignore +0 -2
  4. data/.rubocop.yml +19 -1
  5. data/CHANGELOG.md +53 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +129 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.md +115 -5
  10. data/Rakefile +0 -1
  11. data/gemfiles/with_external_deps.gemfile +2 -0
  12. data/gemfiles/with_external_deps.gemfile.lock +123 -0
  13. data/gemfiles/without_external_deps.gemfile.lock +113 -0
  14. data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
  15. data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
  16. data/lib/qonfig/data_set.rb +3 -0
  17. data/lib/qonfig/imports/direct_key.rb +8 -2
  18. data/lib/qonfig/imports/mappings.rb +8 -2
  19. data/lib/qonfig/loaders/basic.rb +2 -0
  20. data/lib/qonfig/loaders/json.rb +2 -1
  21. data/lib/qonfig/loaders/yaml.rb +3 -1
  22. data/lib/qonfig/plugins/pretty_print/requirements.rb +3 -0
  23. data/lib/qonfig/plugins/pretty_print.rb +1 -0
  24. data/lib/qonfig/plugins/toml/commands/definition/expose_toml.rb +3 -3
  25. data/lib/qonfig/plugins/vault/commands/definition/expose_vault.rb +142 -0
  26. data/lib/qonfig/plugins/vault/commands/definition/load_from_vault.rb +53 -0
  27. data/lib/qonfig/plugins/vault/dsl.rb +35 -0
  28. data/lib/qonfig/plugins/vault/errors.rb +9 -0
  29. data/lib/qonfig/plugins/vault/loaders/vault.rb +74 -0
  30. data/lib/qonfig/plugins/vault.rb +24 -0
  31. data/lib/qonfig/plugins.rb +1 -0
  32. data/lib/qonfig/settings/key_matcher.rb +3 -1
  33. data/lib/qonfig/settings.rb +83 -22
  34. data/lib/qonfig/uploaders/base.rb +2 -0
  35. data/lib/qonfig/uploaders/yaml.rb +2 -0
  36. data/lib/qonfig/version.rb +1 -1
  37. data/lib/qonfig.rb +4 -1
  38. data/qonfig.gemspec +9 -8
  39. data/sig/.keep +0 -0
  40. data/spec/artifacts/.keep +0 -0
  41. data/spec/features/clear_options_spec.rb +92 -0
  42. data/spec/features/compacted_config_spec.rb +308 -0
  43. data/spec/features/composition_spec.rb +207 -0
  44. data/spec/features/config_definition_and_representation_spec.rb +535 -0
  45. data/spec/features/definition_order_spec.rb +69 -0
  46. data/spec/features/dig_functionality_spec.rb +47 -0
  47. data/spec/features/dot_notation_spec.rb +159 -0
  48. data/spec/features/export_settings_spec.rb +138 -0
  49. data/spec/features/expose_json_spec.rb +281 -0
  50. data/spec/features/expose_self/format_option_dynamic_spec.rb +69 -0
  51. data/spec/features/expose_self/format_option_json_spec.rb +74 -0
  52. data/spec/features/expose_self/format_option_unsupported_spec.rb +27 -0
  53. data/spec/features/expose_self/format_option_yaml_spec.rb +77 -0
  54. data/spec/features/expose_self_spec.rb +97 -0
  55. data/spec/features/expose_yaml_spec.rb +263 -0
  56. data/spec/features/freeze_state_spec.rb +122 -0
  57. data/spec/features/get_config_keys_spec.rb +62 -0
  58. data/spec/features/get_config_values_spec.rb +41 -0
  59. data/spec/features/has_a_key_spec.rb +48 -0
  60. data/spec/features/import_settings_spec.rb +323 -0
  61. data/spec/features/indifferent_access_spec.rb +57 -0
  62. data/spec/features/inheritance_spec.rb +110 -0
  63. data/spec/features/instantiation_without_class_definition_spec.rb +59 -0
  64. data/spec/features/iteration_over_setting_keys_spec.rb +48 -0
  65. data/spec/features/load_from_env_spec.rb +240 -0
  66. data/spec/features/load_from_json_spec.rb +97 -0
  67. data/spec/features/load_from_self/format_option_json_spec.rb +31 -0
  68. data/spec/features/load_from_self/format_option_unsupported_spec.rb +27 -0
  69. data/spec/features/load_from_self/format_option_yaml_spec.rb +49 -0
  70. data/spec/features/load_from_self/with_erb_instructions_spec.rb +33 -0
  71. data/spec/features/load_from_self/with_hash_like_data_representation_spec.rb +66 -0
  72. data/spec/features/load_from_self/with_non_hash_like_data_representation_spec.rb +19 -0
  73. data/spec/features/load_from_self/without_end_data_spec.rb +11 -0
  74. data/spec/features/load_from_yaml_spec.rb +110 -0
  75. data/spec/features/load_setting_values_from_file/by_instance_method_examples.rb +171 -0
  76. data/spec/features/load_setting_values_from_file/by_macros_examples.rb +165 -0
  77. data/spec/features/load_setting_values_from_file/load_from_json_spec.rb +21 -0
  78. data/spec/features/load_setting_values_from_file/load_from_self/json_format/end_data_with_env_spec.rb +100 -0
  79. data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_end_data_spec.rb +129 -0
  80. data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_incorrect_end_data_spec.rb +34 -0
  81. data/spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb +65 -0
  82. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/end_data_with_env_spec.rb +94 -0
  83. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_end_data_spec.rb +126 -0
  84. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_incorrect_end_data_spec.rb +32 -0
  85. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/without_end_data_spec.rb +65 -0
  86. data/spec/features/load_setting_values_from_file/load_from_yaml_spec.rb +21 -0
  87. data/spec/features/load_setting_values_from_file/shared_behavior_spec.rb +33 -0
  88. data/spec/features/mixin_spec.rb +387 -0
  89. data/spec/features/non_redefineable_core_methods_spec.rb +29 -0
  90. data/spec/features/plugins/pretty_print_spec.rb +86 -0
  91. data/spec/features/plugins/toml/expose_self/format_option_toml_spec.rb +71 -0
  92. data/spec/features/plugins/toml/expose_toml_spec.rb +221 -0
  93. data/spec/features/plugins/toml/load_from_self/format_option_toml_spec.rb +27 -0
  94. data/spec/features/plugins/toml/load_from_toml_spec.rb +109 -0
  95. data/spec/features/plugins/toml/load_setting_values_from_file/load_from_toml_spec.rb +27 -0
  96. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/end_data_with_env_spec.rb +95 -0
  97. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_end_data_spec.rb +125 -0
  98. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_incorrect_end_data_spec.rb +34 -0
  99. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/without_end_data_spec.rb +65 -0
  100. data/spec/features/plugins/toml/load_setting_values_from_file/shared_behavior_spec.rb +34 -0
  101. data/spec/features/plugins/toml/save_to_toml_spec.rb +149 -0
  102. data/spec/features/plugins/vault/expose_vault_spec.rb +117 -0
  103. data/spec/features/plugins/vault/load_from_vault_spec.rb +80 -0
  104. data/spec/features/plugins_spec.rb +89 -0
  105. data/spec/features/reload_spec.rb +75 -0
  106. data/spec/features/run_code_with_temporary_settings_spec.rb +104 -0
  107. data/spec/features/save_to_file/save_to_json_spec.rb +157 -0
  108. data/spec/features/save_to_file/save_to_yaml_spec.rb +189 -0
  109. data/spec/features/settings_as_predicates_spec.rb +47 -0
  110. data/spec/features/settings_redefinition_spec.rb +30 -0
  111. data/spec/features/slice_functionality_spec.rb +69 -0
  112. data/spec/features/subset_functionality_spec.rb +49 -0
  113. data/spec/features/validation_spec.rb +919 -0
  114. data/spec/fixtures/array_settings.yml +3 -0
  115. data/spec/fixtures/expose_json/incompatible_root_structure.json +6 -0
  116. data/spec/fixtures/expose_json/incompatible_structure.json +4 -0
  117. data/spec/fixtures/expose_json/project.development.json +7 -0
  118. data/spec/fixtures/expose_json/project.json +30 -0
  119. data/spec/fixtures/expose_json/project.production.json +7 -0
  120. data/spec/fixtures/expose_json/project.staging.json +7 -0
  121. data/spec/fixtures/expose_json/project.test.json +7 -0
  122. data/spec/fixtures/expose_yaml/incompatible_structure.yml +2 -0
  123. data/spec/fixtures/expose_yaml/project.development.yml +4 -0
  124. data/spec/fixtures/expose_yaml/project.production.yml +4 -0
  125. data/spec/fixtures/expose_yaml/project.staging.yml +4 -0
  126. data/spec/fixtures/expose_yaml/project.test.yml +4 -0
  127. data/spec/fixtures/expose_yaml/project.yml +25 -0
  128. data/spec/fixtures/json_array_sample.json +14 -0
  129. data/spec/fixtures/json_object_sample.json +9 -0
  130. data/spec/fixtures/json_with_empty_object.json +6 -0
  131. data/spec/fixtures/json_with_erb.json +6 -0
  132. data/spec/fixtures/plugins/toml/expose_toml/project.development.toml +4 -0
  133. data/spec/fixtures/plugins/toml/expose_toml/project.production.toml +4 -0
  134. data/spec/fixtures/plugins/toml/expose_toml/project.staging.toml +4 -0
  135. data/spec/fixtures/plugins/toml/expose_toml/project.test.toml +4 -0
  136. data/spec/fixtures/plugins/toml/expose_toml/project.toml +27 -0
  137. data/spec/fixtures/plugins/toml/mini_file.toml +6 -0
  138. data/spec/fixtures/plugins/toml/toml_sample_with_all_types.toml +72 -0
  139. data/spec/fixtures/plugins/toml/values_file/with_env.toml +13 -0
  140. data/spec/fixtures/plugins/toml/values_file/without_env.toml +6 -0
  141. data/spec/fixtures/rubocop_settings.yml +12 -0
  142. data/spec/fixtures/shared_settings_with_aliases.yml +10 -0
  143. data/spec/fixtures/travis_settings.yml +6 -0
  144. data/spec/fixtures/values_file/with_env.json +19 -0
  145. data/spec/fixtures/values_file/with_env.yml +17 -0
  146. data/spec/fixtures/values_file/without_env.json +8 -0
  147. data/spec/fixtures/values_file/without_env.yml +5 -0
  148. data/spec/fixtures/with_empty_hash.yml +4 -0
  149. data/spec/fixtures/with_erb_instructions.yml +3 -0
  150. data/spec/spec_helper.rb +46 -0
  151. data/spec/support/meta_scopes.rb +20 -0
  152. data/spec/support/spec_support.rb +42 -0
  153. metadata +181 -15
  154. data/.travis.yml +0 -47
@@ -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
- def [](key)
139
- __lock__.thread_safe_access do
140
- begin
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
- # rubocop:disable Layout/LineLength
221
- def __to_hash__(transform_key: BASIC_SETTING_KEY_TRANSFORMER, transform_value: BASIC_SETTING_VALUE_TRANSFORMER)
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(Qonfig::IncorrectKeyTransformerError, 'Key transformer should be a type of proc')
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(Qonfig::IncorrectValueTransformerError, 'Value transformer should be a type of proc')
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
- __build_hash_representation__(transform_key: transform_key, transform_value: transform_value)
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 Layout/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 = __get_value__(keys.first)
564
- rest_keys = Array(keys[1..-1])
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(&method(:__indifferently_accessable_option_key__))
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.2.0
671
- def __build_hash_representation__(options_part = __options__, transform_key:, transform_value:)
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] = __build_hash_representation__(
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]
@@ -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
@@ -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?
@@ -5,5 +5,5 @@ module Qonfig
5
5
  #
6
6
  # @api public
7
7
  # @since 0.1.0
8
- VERSION = '0.24.0'
8
+ VERSION = '0.27.0'
9
9
  end
data/lib/qonfig.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'set'
3
4
  require 'yaml'
4
5
  require 'json'
5
6
  require 'erb'
@@ -57,10 +58,12 @@ module Qonfig
57
58
  # @since 0.20.0
58
59
  define_validator(:module) { |value| value.is_a?(Module) }
59
60
  # @since 0.20.0
60
- define_validator(:not_nil) { |value| !value.nil? }
61
+ define_validator(:not_nil) { |value| value == nil }
61
62
 
62
63
  # @since 0.12.0
63
64
  register_plugin('toml', Qonfig::Plugins::TOML)
64
65
  # @since 0.19.0
65
66
  register_plugin('pretty_print', Qonfig::Plugins::PrettyPrint)
67
+ # @since 0.25.0
68
+ register_plugin('vault', Qonfig::Plugins::Vault)
66
69
  end
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'
9
+ spec.required_ruby_version = '>= 2.6.0'
10
10
 
11
11
  spec.name = 'qonfig'
12
12
  spec.version = Qonfig::VERSION
@@ -25,15 +25,16 @@ 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").reject do |f|
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 'simplecov', '~> 0.17'
33
- spec.add_development_dependency 'rspec', '~> 3.9'
34
- spec.add_development_dependency 'armitage-rubocop', '~> 0.78'
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'
35
33
 
36
34
  spec.add_development_dependency 'bundler'
37
- spec.add_development_dependency 'rake', '>= 13'
35
+ spec.add_development_dependency 'bundler-audit'
36
+ spec.add_development_dependency 'ci-helper'
38
37
  spec.add_development_dependency 'pry'
38
+ spec.add_development_dependency 'rake', '>= 13'
39
+ spec.add_development_dependency 'simplecov-lcov'
39
40
  end
data/sig/.keep ADDED
File without changes
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