qonfig 0.22.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.rubocop.yml +19 -1
  4. data/.travis.yml +28 -20
  5. data/CHANGELOG.md +57 -1
  6. data/Gemfile.lock +102 -0
  7. data/LICENSE.txt +1 -1
  8. data/README.md +125 -9
  9. data/Rakefile +0 -1
  10. data/bin/rspec +1 -0
  11. data/gemfiles/with_external_deps.gemfile +2 -0
  12. data/gemfiles/with_external_deps.gemfile.lock +112 -0
  13. data/gemfiles/without_external_deps.gemfile.lock +102 -0
  14. data/lib/qonfig.rb +4 -1
  15. data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
  16. data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
  17. data/lib/qonfig/data_set.rb +5 -2
  18. data/lib/qonfig/dsl.rb +2 -2
  19. data/lib/qonfig/imports/direct_key.rb +8 -2
  20. data/lib/qonfig/imports/mappings.rb +8 -2
  21. data/lib/qonfig/loaders/basic.rb +2 -0
  22. data/lib/qonfig/loaders/json.rb +2 -1
  23. data/lib/qonfig/plugins.rb +1 -0
  24. data/lib/qonfig/plugins/pretty_print.rb +8 -1
  25. data/lib/qonfig/plugins/pretty_print/requirements.rb +3 -0
  26. data/lib/qonfig/plugins/pretty_print/ruby_2_7_basic_object_pp_patch.rb +44 -0
  27. data/lib/qonfig/plugins/toml/commands/definition/expose_toml.rb +4 -4
  28. data/lib/qonfig/plugins/toml/commands/definition/load_from_toml.rb +1 -1
  29. data/lib/qonfig/plugins/toml/data_set.rb +2 -2
  30. data/lib/qonfig/plugins/toml/dsl.rb +2 -2
  31. data/lib/qonfig/plugins/vault.rb +24 -0
  32. data/lib/qonfig/plugins/vault/commands/definition/expose_vault.rb +142 -0
  33. data/lib/qonfig/plugins/vault/commands/definition/load_from_vault.rb +53 -0
  34. data/lib/qonfig/plugins/vault/dsl.rb +35 -0
  35. data/lib/qonfig/plugins/vault/errors.rb +9 -0
  36. data/lib/qonfig/plugins/vault/loaders/vault.rb +73 -0
  37. data/lib/qonfig/settings.rb +83 -22
  38. data/lib/qonfig/settings/key_matcher.rb +3 -1
  39. data/lib/qonfig/uploaders/base.rb +2 -0
  40. data/lib/qonfig/uploaders/file.rb +2 -2
  41. data/lib/qonfig/uploaders/yaml.rb +3 -1
  42. data/lib/qonfig/version.rb +1 -1
  43. data/qonfig.gemspec +6 -9
  44. data/sig/.keep +0 -0
  45. data/spec/features/clear_options_spec.rb +92 -0
  46. data/spec/features/compacted_config_spec.rb +308 -0
  47. data/spec/features/composition_spec.rb +207 -0
  48. data/spec/features/config_definition_and_representation_spec.rb +535 -0
  49. data/spec/features/definition_order_spec.rb +69 -0
  50. data/spec/features/dig_functionality_spec.rb +47 -0
  51. data/spec/features/dot_notation_spec.rb +159 -0
  52. data/spec/features/export_settings_spec.rb +138 -0
  53. data/spec/features/expose_json_spec.rb +281 -0
  54. data/spec/features/expose_self/format_option_dynamic_spec.rb +69 -0
  55. data/spec/features/expose_self/format_option_json_spec.rb +74 -0
  56. data/spec/features/expose_self/format_option_unsupported_spec.rb +27 -0
  57. data/spec/features/expose_self/format_option_yaml_spec.rb +77 -0
  58. data/spec/features/expose_self_spec.rb +97 -0
  59. data/spec/features/expose_yaml_spec.rb +263 -0
  60. data/spec/features/freeze_state_spec.rb +122 -0
  61. data/spec/features/get_config_keys_spec.rb +62 -0
  62. data/spec/features/get_config_values_spec.rb +41 -0
  63. data/spec/features/has_a_key_spec.rb +48 -0
  64. data/spec/features/import_settings_spec.rb +323 -0
  65. data/spec/features/indifferent_access_spec.rb +57 -0
  66. data/spec/features/inheritance_spec.rb +110 -0
  67. data/spec/features/instantiation_without_class_definition_spec.rb +59 -0
  68. data/spec/features/iteration_over_setting_keys_spec.rb +48 -0
  69. data/spec/features/load_from_env_spec.rb +240 -0
  70. data/spec/features/load_from_json_spec.rb +97 -0
  71. data/spec/features/load_from_self/format_option_json_spec.rb +31 -0
  72. data/spec/features/load_from_self/format_option_unsupported_spec.rb +27 -0
  73. data/spec/features/load_from_self/format_option_yaml_spec.rb +49 -0
  74. data/spec/features/load_from_self/with_erb_instructions_spec.rb +33 -0
  75. data/spec/features/load_from_self/with_hash_like_data_representation_spec.rb +66 -0
  76. data/spec/features/load_from_self/with_non_hash_like_data_representation_spec.rb +19 -0
  77. data/spec/features/load_from_self/without_end_data_spec.rb +11 -0
  78. data/spec/features/load_from_yaml_spec.rb +110 -0
  79. data/spec/features/load_setting_values_from_file/by_instance_method_examples.rb +171 -0
  80. data/spec/features/load_setting_values_from_file/by_macros_examples.rb +165 -0
  81. data/spec/features/load_setting_values_from_file/load_from_json_spec.rb +21 -0
  82. data/spec/features/load_setting_values_from_file/load_from_self/json_format/end_data_with_env_spec.rb +100 -0
  83. data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_end_data_spec.rb +129 -0
  84. data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_incorrect_end_data_spec.rb +34 -0
  85. data/spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb +65 -0
  86. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/end_data_with_env_spec.rb +94 -0
  87. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_end_data_spec.rb +126 -0
  88. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_incorrect_end_data_spec.rb +32 -0
  89. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/without_end_data_spec.rb +65 -0
  90. data/spec/features/load_setting_values_from_file/load_from_yaml_spec.rb +21 -0
  91. data/spec/features/load_setting_values_from_file/shared_behavior_spec.rb +33 -0
  92. data/spec/features/mixin_spec.rb +387 -0
  93. data/spec/features/non_redefineable_core_methods_spec.rb +29 -0
  94. data/spec/features/plugins/pretty_print_spec.rb +86 -0
  95. data/spec/features/plugins/toml/expose_self/format_option_toml_spec.rb +71 -0
  96. data/spec/features/plugins/toml/expose_toml_spec.rb +221 -0
  97. data/spec/features/plugins/toml/load_from_self/format_option_toml_spec.rb +27 -0
  98. data/spec/features/plugins/toml/load_from_toml_spec.rb +109 -0
  99. data/spec/features/plugins/toml/load_setting_values_from_file/load_from_toml_spec.rb +27 -0
  100. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/end_data_with_env_spec.rb +95 -0
  101. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_end_data_spec.rb +125 -0
  102. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_incorrect_end_data_spec.rb +34 -0
  103. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/without_end_data_spec.rb +65 -0
  104. data/spec/features/plugins/toml/load_setting_values_from_file/shared_behavior_spec.rb +34 -0
  105. data/spec/features/plugins/toml/save_to_toml_spec.rb +149 -0
  106. data/spec/features/plugins/vault/expose_vault_spec.rb +117 -0
  107. data/spec/features/plugins/vault/load_from_vault_spec.rb +80 -0
  108. data/spec/features/plugins_spec.rb +89 -0
  109. data/spec/features/reload_spec.rb +75 -0
  110. data/spec/features/run_code_with_temporary_settings_spec.rb +104 -0
  111. data/spec/features/save_to_file/save_to_json_spec.rb +157 -0
  112. data/spec/features/save_to_file/save_to_yaml_spec.rb +189 -0
  113. data/spec/features/settings_as_predicates_spec.rb +47 -0
  114. data/spec/features/settings_redefinition_spec.rb +30 -0
  115. data/spec/features/slice_functionality_spec.rb +69 -0
  116. data/spec/features/subset_functionality_spec.rb +49 -0
  117. data/spec/features/validation_spec.rb +916 -0
  118. data/spec/fixtures/array_settings.yml +3 -0
  119. data/spec/fixtures/expose_json/incompatible_root_structure.json +6 -0
  120. data/spec/fixtures/expose_json/incompatible_structure.json +4 -0
  121. data/spec/fixtures/expose_json/project.development.json +7 -0
  122. data/spec/fixtures/expose_json/project.json +30 -0
  123. data/spec/fixtures/expose_json/project.production.json +7 -0
  124. data/spec/fixtures/expose_json/project.staging.json +7 -0
  125. data/spec/fixtures/expose_json/project.test.json +7 -0
  126. data/spec/fixtures/expose_yaml/incompatible_structure.yml +2 -0
  127. data/spec/fixtures/expose_yaml/project.development.yml +4 -0
  128. data/spec/fixtures/expose_yaml/project.production.yml +4 -0
  129. data/spec/fixtures/expose_yaml/project.staging.yml +4 -0
  130. data/spec/fixtures/expose_yaml/project.test.yml +4 -0
  131. data/spec/fixtures/expose_yaml/project.yml +25 -0
  132. data/spec/fixtures/json_array_sample.json +14 -0
  133. data/spec/fixtures/json_object_sample.json +9 -0
  134. data/spec/fixtures/json_with_empty_object.json +6 -0
  135. data/spec/fixtures/json_with_erb.json +6 -0
  136. data/spec/fixtures/plugins/toml/expose_toml/project.development.toml +4 -0
  137. data/spec/fixtures/plugins/toml/expose_toml/project.production.toml +4 -0
  138. data/spec/fixtures/plugins/toml/expose_toml/project.staging.toml +4 -0
  139. data/spec/fixtures/plugins/toml/expose_toml/project.test.toml +4 -0
  140. data/spec/fixtures/plugins/toml/expose_toml/project.toml +27 -0
  141. data/spec/fixtures/plugins/toml/mini_file.toml +6 -0
  142. data/spec/fixtures/plugins/toml/toml_sample_with_all_types.toml +72 -0
  143. data/spec/fixtures/plugins/toml/values_file/with_env.toml +13 -0
  144. data/spec/fixtures/plugins/toml/values_file/without_env.toml +6 -0
  145. data/spec/fixtures/rubocop_settings.yml +12 -0
  146. data/spec/fixtures/shared_settings_with_aliases.yml +10 -0
  147. data/spec/fixtures/travis_settings.yml +6 -0
  148. data/spec/fixtures/values_file/with_env.json +19 -0
  149. data/spec/fixtures/values_file/with_env.yml +17 -0
  150. data/spec/fixtures/values_file/without_env.json +8 -0
  151. data/spec/fixtures/values_file/without_env.yml +5 -0
  152. data/spec/fixtures/with_empty_hash.yml +4 -0
  153. data/spec/fixtures/with_erb_instructions.yml +3 -0
  154. data/spec/spec_helper.rb +27 -0
  155. data/spec/support/meta_scopes.rb +20 -0
  156. data/spec/support/spec_support.rb +42 -0
  157. metadata +140 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48f718feaf6da5ef0dd8e81bad25fa58b7b06c2eb120b692c6111b745a507c4d
4
- data.tar.gz: ad50f7258506db6837c0d08c9c6efaf003f12291427ec33c5b0f8c15124bfdfc
3
+ metadata.gz: cc38d7dba82dac66de4b7c240ae589cde85ff7266e87ae8055df1706d0877ebf
4
+ data.tar.gz: 213899d6509a51c3ac0434cf9a60467460a61294788a3489e6088417d4c82214
5
5
  SHA512:
6
- metadata.gz: eb496fb435d1c6a203960ad98a36f2afac9efe5efd0d8a2466187f89c8df3a87af7a7c3678cd07fc73bacd10ca1ae1430a555d396d5783fcad58931cd2f08a1d
7
- data.tar.gz: 926c610a00683e0a4cdbd2663777f95579a02c5a11e8548bdfb990a2c962e518e3797c5814a321be2cdc1e531e7855a20913d66bf0c6927f115b0106b30b050a
6
+ metadata.gz: f285e423068f4e5d56e6b0bb74a23c027a6056683ba8c873d37995f733edac9eacdf98a8e2f7222d45fb3fe5d55fc42218f55942a644cfdd7381f2620e0f9903
7
+ data.tar.gz: eb17c02d38048fa1004055b8b7ca19f757885d11e0ec20c716f9c81cfde73ddb1b470a3fee4e79a8bb8be759abbe18dbbb1ee734326ee56b9683c11db567b1fc
data/.gitignore CHANGED
@@ -7,10 +7,8 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  .rspec_status
10
- Gemfile.lock
11
10
  /.idea
12
11
  .ruby-version
13
12
  /.vscode/
14
13
  /spec/artifacts/
15
- /gemfiles/*.gemfile.lock
16
14
  *.gem
data/.rubocop.yml CHANGED
@@ -5,13 +5,15 @@ inherit_gem:
5
5
  - lib/rubocop.rspec.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.6.5
8
+ TargetRubyVersion: 3.0.0
9
+ NewCops: enable
9
10
  Include:
10
11
  - lib/**/*.rb
11
12
  - spec/**/*.rb
12
13
  - Gemfile
13
14
  - Rakefile
14
15
  - qonfig.gemspec
16
+ - gemfiles/*.gemfile
15
17
  - bin/console
16
18
  - bin/rspec
17
19
 
@@ -26,3 +28,19 @@ Style/RedundantBegin:
26
28
  # NOTE: too situative
27
29
  Metrics/ParameterLists:
28
30
  Enabled: false
31
+
32
+ # NOTE: too situative in current code base
33
+ Style/NilComparison:
34
+ Enabled: false
35
+
36
+ # NOTE: too situative in current code base
37
+ Style/NonNilCheck:
38
+ Enabled: false
39
+
40
+ # NOTE: too situative in current code base
41
+ Lint/MissingSuper:
42
+ Enabled: false
43
+
44
+ # NOTE: too situative in current code base
45
+ Lint/EmptyBlock:
46
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,30 +1,45 @@
1
1
  language: ruby
2
- matrix:
2
+ os: linux
3
+ dist: xenial
4
+ cache: bundler
5
+ before_install: gem install bundler
6
+ script: bundle exec rspec
7
+ jobs:
3
8
  fast_finish: true
4
9
  include:
5
- - rvm: 2.4.9
10
+ - rvm: 2.4.10
11
+ gemfile: gemfiles/with_external_deps.gemfile
12
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
13
+ - rvm: 2.5.8
14
+ gemfile: gemfiles/with_external_deps.gemfile
15
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
16
+ - rvm: 2.6.6
6
17
  gemfile: gemfiles/with_external_deps.gemfile
7
- env: TEST_PLUGINS=true
8
- - rvm: 2.5.7
18
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
19
+ - rvm: 2.7.2
9
20
  gemfile: gemfiles/with_external_deps.gemfile
10
- env: TEST_PLUGINS=true
11
- - rvm: 2.6.5
21
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
22
+ - rvm: 3.0.0
12
23
  gemfile: gemfiles/with_external_deps.gemfile
13
- env: TEST_PLUGINS=true
24
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
14
25
  - rvm: ruby-head
15
26
  gemfile: gemfiles/with_external_deps.gemfile
16
- env: TEST_PLUGINS=true
27
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
17
28
  - rvm: jruby-head
18
29
  gemfile: gemfiles/with_external_deps.gemfile
19
- env: TEST_PLUGINS=true
30
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
20
31
  - rvm: truffleruby
21
32
  gemfile: gemfiles/with_external_deps.gemfile
22
- env: TEST_PLUGINS=true
23
- - rvm: 2.4.9
33
+ env: TEST_PLUGINS=true FULL_TEST_COVERAGE_CHECK=true
34
+ - rvm: 2.4.10
24
35
  gemfile: gemfiles/without_external_deps.gemfile
25
- - rvm: 2.5.7
36
+ - rvm: 2.5.8
26
37
  gemfile: gemfiles/without_external_deps.gemfile
27
- - rvm: 2.6.5
38
+ - rvm: 2.6.6
39
+ gemfile: gemfiles/without_external_deps.gemfile
40
+ - rvm: 2.7.2
41
+ gemfile: gemfiles/without_external_deps.gemfile
42
+ - rvm: 3.0.0
28
43
  gemfile: gemfiles/without_external_deps.gemfile
29
44
  - rvm: ruby-head
30
45
  gemfile: gemfiles/without_external_deps.gemfile
@@ -36,10 +51,3 @@ matrix:
36
51
  - rvm: ruby-head
37
52
  - rvm: jruby-head
38
53
  - rvm: truffleruby
39
- sudo: false
40
- cache: bundler
41
- before_install: gem install bundler
42
- script: bundle exec rspec
43
- notifications:
44
- slack:
45
- secure: I03SDv+IrKy3IkeGjjHUJ9VneFMiYpLzIgPOixGFO5zGVXgulwmun82KsrPSW5HkK1UEQCahfoXt1hNECPwxcdsY01q6LBYJQx1jD0q17bXHllN/q0C6lx3peRN0KqNAAOU3/mHZxLt3HFV+N3HsSnoxDMuSYJgKbjCL/QVG2L2UYT9vi+JRNM/thj8R6MWKWlOHemik40GbLr2anCOCqiALzxnJzh5nJyGj+9SGvjhHfQq/fAIrg1+Scu+UchG8d+1yS5JWsGTt1/JF08i+Ux4ceTQ7GNBNeA5cj/xuUzvRx6A85renxyTiZMKIL0+jeceUm8c+/46XFcq0F7/kJB36lwjFhX1JRphcu/VouRdEwW/BvH74wnyHtygqOpk0LH4shp7A1DIS1DlnBbeJxrR5hdMDnmV85kTU6w6H0BbncsYY/pH1fji1kgH6jCsdwqDlq4wLB8x8I+eZABBsfb/r55z/HnBmmxlvR7Rt3X5/yR3gJrsgRrDBBZ5LwYy1RSCDu76vMQqWGJKG03FdfqSNqmC5V4MC5Ez8yjGDW0Yle09mwvsL2c6fDXyDPCeB/gwNk+FvgLRXnv7C4BaBNEoG4JnCL/dwauoJNg0lB6uF34BEmYAhZIrdY1CI6BqPWnaVMJfcJSYekBVXDIELDnTFRWjaGU1y8dM6lNzDmYE=
data/CHANGELOG.md CHANGED
@@ -1,6 +1,62 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.26.0] - 2021-07-01
5
+ ### Added
6
+ - Support `ERB` in `load_from_json` method;
7
+
8
+ ## [0.25.0] - 2020-09-15
9
+ ### Added
10
+ - Support for **Vault** config provider:
11
+ - realized as a plugin (`Qonfig.plugin(:vault)`);
12
+ - provides `#load_from_vault`, `#expose_vault` methods and works in `#*_yaml`-like manner);
13
+ - depends on `gem vault (>= 0.1)`
14
+ - `Qonfig::Settings#[]` behave like `Qonfig::Settings#__dig__`;
15
+ - An ability to represent the config hash in dot-notated style (all config keys are represented in dot-notated format):
16
+ - works via `#to_h(dot_style: true)`;
17
+ - `key_transformer:` and `value_transfomer:` options are supported too;
18
+
19
+ ```ruby
20
+ class Config << Qonfig::DataSet
21
+ setting :database do
22
+ setting :host, 'localhost'
23
+ setting :port, 6432
24
+ end
25
+
26
+ setting :api do
27
+ setting :rest_enabled, true
28
+ setting :rpc_enabled, false
29
+ end
30
+ end
31
+
32
+ Config.new.to_h(dot_style: true)
33
+ # =>
34
+ {
35
+ 'database.host' => 'localhost',
36
+ 'database.port' => 6432,
37
+ 'api.rest_enabled' => true,
38
+ 'api.rpc_enabled' => false,
39
+ }
40
+ ```
41
+
42
+ ## [0.24.1] - 2020-03-10
43
+ ### Changed
44
+ - Enhanced dot-notated key resolving algorithm: now it goes through the all dot-notated key parts
45
+ until it finds the required setting key (or fails with `Qonfig::UnknowSettingKeyError`);
46
+
47
+ ### Fixed
48
+ - (**Pretty-Print Plugin**):
49
+ - dot-noted setting keys can not be pretty-printed (they raise `Qonfig::UnknownSettingKeyError`);
50
+ - added `set` and `pp` as preloaded dependencies;
51
+
52
+ ## [0.24.0] - 2019-12-29
53
+ ### Added
54
+ - Support for **Ruby@2.7**;
55
+
56
+ ## [0.23.0] - 2019-12-12
57
+ ### Added
58
+ - Support for `Pathname` file path in `.load_from_json`, `.load_from_yaml`, `.load_from_toml`, `.expose_yaml`, `.expose_json`, `.expose_toml`;
59
+
4
60
  ## [0.22.0] - 2019-12-12
5
61
  ### Added
6
62
  - Support for `Pathname` file path in `.values_file`, `#load_from_file`, `#load_from_yaml`, `#load_from_json` and `#load_from_toml`;
@@ -11,7 +67,7 @@ All notable changes to this project will be documented in this file.
11
67
  - represents the compacted config object with setting readers and setting writers only;
12
68
  - setting keys are represented as direct instace methods (`#settings` invokation does not need);
13
69
  - no any other useful instance-based functionality;
14
- - full support of `Qonfig::DataSet` DSL commands (`setting`, `validate`, `add_validator`, `load_from_x`/`expose_x` and etc);
70
+ - full support of `Qonfig::DataSet` DSL commands (`.setting`, `.validate`, `.add_validator`, `.load_from_x`/`.expose_x` and etc);
15
71
  - can be instantiated by:
16
72
  - by existing config object: `Qonfig::DataSet#compacted` or `Qonfig::Compacted.build_from(config, &configuration)`
17
73
  - by direct instantiation: `Qonfig::Compacted.new(settings_values = {}, &configuration)`;
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qonfig (0.26.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activesupport (6.1.0)
10
+ concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ i18n (>= 1.6, < 2)
12
+ minitest (>= 5.1)
13
+ tzinfo (~> 2.0)
14
+ zeitwerk (~> 2.3)
15
+ armitage-rubocop (1.7.0.1)
16
+ rubocop (= 1.7.0)
17
+ rubocop-performance (= 1.9.1)
18
+ rubocop-rails (= 2.9.1)
19
+ rubocop-rake (= 0.5.1)
20
+ rubocop-rspec (= 2.1.0)
21
+ ast (2.4.1)
22
+ coderay (1.1.3)
23
+ concurrent-ruby (1.1.7)
24
+ diff-lcs (1.4.4)
25
+ docile (1.3.4)
26
+ i18n (1.8.5)
27
+ concurrent-ruby (~> 1.0)
28
+ method_source (1.0.0)
29
+ minitest (5.14.2)
30
+ parallel (1.20.1)
31
+ parser (3.0.0.0)
32
+ ast (~> 2.4.1)
33
+ pry (0.13.1)
34
+ coderay (~> 1.1)
35
+ method_source (~> 1.0)
36
+ rack (2.2.3)
37
+ rainbow (3.0.0)
38
+ rake (13.0.3)
39
+ regexp_parser (2.0.2)
40
+ rexml (3.2.4)
41
+ rspec (3.10.0)
42
+ rspec-core (~> 3.10.0)
43
+ rspec-expectations (~> 3.10.0)
44
+ rspec-mocks (~> 3.10.0)
45
+ rspec-core (3.10.0)
46
+ rspec-support (~> 3.10.0)
47
+ rspec-expectations (3.10.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.10.0)
50
+ rspec-mocks (3.10.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.10.0)
53
+ rspec-support (3.10.0)
54
+ rubocop (1.7.0)
55
+ parallel (~> 1.10)
56
+ parser (>= 2.7.1.5)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml
60
+ rubocop-ast (>= 1.2.0, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 1.4.0, < 2.0)
63
+ rubocop-ast (1.3.0)
64
+ parser (>= 2.7.1.5)
65
+ rubocop-performance (1.9.1)
66
+ rubocop (>= 0.90.0, < 2.0)
67
+ rubocop-ast (>= 0.4.0)
68
+ rubocop-rails (2.9.1)
69
+ activesupport (>= 4.2.0)
70
+ rack (>= 1.1)
71
+ rubocop (>= 0.90.0, < 2.0)
72
+ rubocop-rake (0.5.1)
73
+ rubocop
74
+ rubocop-rspec (2.1.0)
75
+ rubocop (~> 1.0)
76
+ rubocop-ast (>= 1.1.0)
77
+ ruby-progressbar (1.10.1)
78
+ simplecov (0.20.0)
79
+ docile (~> 1.1)
80
+ simplecov-html (~> 0.11)
81
+ simplecov_json_formatter (~> 0.1)
82
+ simplecov-html (0.12.3)
83
+ simplecov_json_formatter (0.1.2)
84
+ tzinfo (2.0.4)
85
+ concurrent-ruby (~> 1.0)
86
+ unicode-display_width (1.7.0)
87
+ zeitwerk (2.4.2)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ armitage-rubocop (~> 1.7)
94
+ bundler
95
+ pry
96
+ qonfig!
97
+ rake (>= 13)
98
+ rspec (~> 3.10)
99
+ simplecov (~> 0.20)
100
+
101
+ BUNDLED WITH
102
+ 2.2.21
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2019 Rustam Ibragimov
3
+ Copyright (c) 2018-2020 Rustam Ibragimov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -40,6 +40,9 @@ require 'qonfig'
40
40
  - [Inheritance](#inheritance)
41
41
  - [Composition](#composition)
42
42
  - [Hash representation](#hash-representation)
43
+ - [Default behaviour (without options)](#default-behavior-without-options)
44
+ - [With transformations](#with-transformations)
45
+ - [Dot-style format](#dot-style-format)
43
46
  - [Smart Mixin](#smart-mixin) (`Qonfig::Configurable`)
44
47
  - [Instantiation without class definition](#instantiation-without-class-definition) (`Qonfig::DataSet.build(&definitions)`)
45
48
  - [Compacted config](#compacted-config)
@@ -102,7 +105,9 @@ require 'qonfig'
102
105
  - [Plugins](#plugins)
103
106
  - [toml](#plugins-toml) (support for `TOML` format)
104
107
  - [pretty_print](#plugins-pretty_print) (beautified/prettified console output)
108
+ - [vault](#plugins-vault) (support for `Vault` store)
105
109
  - [Roadmap](#roadmap)
110
+ - [Build](#build)
106
111
  ---
107
112
 
108
113
  ## Definition
@@ -187,6 +192,10 @@ config.settings['vendor_api']['domain'] # => 'app.service.com'
187
192
  config.settings['vendor_api']['login'] # => 'test_user'
188
193
  config.settings['enable_graphql'] # => false
189
194
 
195
+ # dig to value
196
+ config.settings[:vendor_api, :domain] # => 'app.service.com'
197
+ config.settings[:vendor_api, 'login'] # => 'test_user'
198
+
190
199
  # get option value directly via index (with indifferent access)
191
200
  config['project_id'] # => nil
192
201
  config['enable_graphql'] # => false
@@ -270,7 +279,7 @@ config.slice_value('vendor_api.port') # => Qonfig::UnknownSettingError # (key do
270
279
  # - get a subset (a set of sets) of config settings represented as a hash;
271
280
  # - each key (or key set) represents a requirement of a certain setting key;
272
281
 
273
- config.subet(:vendor_api, :enable_graphql)
282
+ config.subset(:vendor_api, :enable_graphql)
274
283
  # => { 'vendor_api' => { 'login' => ..., 'domain' => ... }, 'enable_graphql' => false }
275
284
 
276
285
  config.subset(:project_id, [:vendor_api, :domain], [:credentials, :user, :login])
@@ -435,6 +444,12 @@ project_config.settings.db.password # => 'testpaswd'
435
444
 
436
445
  ### Hash representation
437
446
 
447
+ - works via `#to_h` and `#to_hash`;
448
+ - supported options:
449
+ - `key_transformer:` - an optional proc that accepts setting key and makes your custom transformations;
450
+ - `value_transformer:` - an optional proc that accepts setting value and makes your custom transformations;
451
+ - `dot_style:` - (`false` by default) represent setting keys in dot-notation (transformations are supported too);
452
+
438
453
  ```ruby
439
454
  class Config < Qonfig::DataSet
440
455
  setting :serializers do
@@ -453,9 +468,13 @@ class Config < Qonfig::DataSet
453
468
 
454
469
  setting :logger, Logger.new(STDOUT)
455
470
  end
471
+ ```
456
472
 
457
- Config.new.to_h
473
+ #### Default behavior (without-options)
458
474
 
475
+ ```ruby
476
+ Config.new.to_h
477
+ # =>
459
478
  {
460
479
  "serializers": {
461
480
  "json" => { "engine" => :ok },
@@ -466,6 +485,55 @@ Config.new.to_h
466
485
  }
467
486
  ```
468
487
 
488
+ #### With transformations
489
+
490
+ - with `key_transformer` and/or `value_transformer`;
491
+
492
+ ```ruby
493
+ key_transformer = -> (key) { "#{key}!!" }
494
+ value_transformer = -> (value) { "#{value}??" }
495
+
496
+ Config.new.to_h(key_transformer: key_transformer, value_transformer: value_transformer)
497
+ # =>
498
+ {
499
+ "serializers!!": {
500
+ "json!!" => { "engine!!" => "ok??" },
501
+ "hash!!" => { "engine!!" => "native??" },
502
+ },
503
+ "adapter!!" => { "default!!" => "memory_sync??" },
504
+ "logger!!" => "#<Logger:0x00007fcde799f158>??"
505
+ }
506
+ ```
507
+
508
+ #### Dot-style format
509
+
510
+ - transformations are supported too (`key_transformer` and `value_transformer`);
511
+
512
+ ```ruby
513
+ Config.new.to_h(dot_style: true)
514
+ # =>
515
+ {
516
+ "serializers.json.engine" => :ok,
517
+ "serializers.hash.engine" => :native,
518
+ "adapter.default" => :memory_sync,
519
+ "logger" => #<Logger:0x4b0d79fc>,
520
+ }
521
+ ```
522
+
523
+ ```ruby
524
+ transformer = -> (value) { "$$#{value}$$" }
525
+
526
+ Config.new.to_h(dot_style: true, key_transformer: transformer, value_transformer: transformer)
527
+
528
+ # => "#<Logger:0x00007fcde799f158>??"
529
+ {
530
+ "$$serializers.json.engine$$" => "$$ok$$",
531
+ "$$serializers.hash.engine$$" => "$$native$$",
532
+ "$$adapter.default$$" => "$$memory_sync$$",
533
+ "$$logger$$" => "$$#<Logger:0x00007fcde799f158>$$",
534
+ }
535
+ ```
536
+
469
537
  ---
470
538
 
471
539
  ### Smart Mixin
@@ -633,9 +701,8 @@ config.settings.web_api # => "api.google.com"
633
701
 
634
702
  ---
635
703
 
636
- - `Qonfig::Compacted`: represents the compacted config object with setting readers and setting writers;
704
+ - `Qonfig::Compacted`: represents the compacted config object with setting readers, setting writers and setting predicates only - and no any other useful instance-based functionality:
637
705
  - setting keys are represented as direct instace methods (`#settings` invokation does not need);
638
- - no any other useful instance-based functionality - just setting readers, setting writers and setting predicates:
639
706
  - support for index-like access methods (`[]`,`[]=`);
640
707
  - full support of `Qonfig::DataSet` definition DSL commands:
641
708
  - `setting`, `re_setting` [doc](#definition-and-access)
@@ -646,9 +713,9 @@ config.settings.web_api # => "api.google.com"
646
713
  - support for validation of potential setting values `.valid_with?` [documentation](#validation-of-potential-setting-values);
647
714
  - can be instantiated by:
648
715
  - by existing config object: `Qonfig::DataSet#compacted` or `Qonfig::Compacted.build_from(config, &configuration)`;
649
- - from existing `Qonfig::DataSet` class: ``Qonfig::DataSet.build_compacted`;
716
+ - from existing `Qonfig::DataSet` class: `Qonfig::DataSet.build_compacted`;
650
717
  - by direct instantiation: `Qonfig::Compacted.new(settings_values = {}, &configuration)`;
651
- - by implicit instance building without explicit class definition `Qonfig::Compacted.build(&dsl_commands) # => instance of Qonfig::Compacted`;
718
+ - by implicit instance building without explicit class definition `Qonfig::Compacted.build(&dsl_commands)`;
652
719
  - you can define your own instance methods too;
653
720
 
654
721
  ---
@@ -1001,6 +1068,8 @@ config.root_keys
1001
1068
  - method signature: `#reload!(configurations = {}, &configuration)`;
1002
1069
 
1003
1070
  ```ruby
1071
+ # -- config example ---
1072
+
1004
1073
  class Config < Qonfig::DataSet
1005
1074
  setting :db do
1006
1075
  setting :adapter, 'postgresql'
@@ -1013,6 +1082,10 @@ config = Config.new
1013
1082
 
1014
1083
  config.settings.db.adapter # => 'postgresql'
1015
1084
  config.settings.logger # => #<Logger:0x00007ff9>
1085
+ ```
1086
+
1087
+ ```ruby
1088
+ # --- redefine some settings (or add a new one) --
1016
1089
 
1017
1090
  config.configure { |conf| conf.logger = nil } # redefine some settings (will be reloaded)
1018
1091
 
@@ -1024,6 +1097,10 @@ class Config
1024
1097
 
1025
1098
  setting :enable_api, false # append new setting
1026
1099
  end
1100
+ ```
1101
+
1102
+ ```ruby
1103
+ # --- reload ---
1027
1104
 
1028
1105
  # reload settings
1029
1106
  config.reload!
@@ -2163,6 +2240,7 @@ config.settings.web.password # => staging_password (from sidekiq.staging.yml)
2163
2240
 
2164
2241
  ### Load from JSON file
2165
2242
 
2243
+ - supports `ERB`;
2166
2244
  - `:strict` mode (fail behaviour when the required yaml file doesnt exist):
2167
2245
  - `true` (by default) - causes `Qonfig::FileNotFoundError`;
2168
2246
  - `false` - do nothing, ignore current command;
@@ -3081,6 +3159,7 @@ dynamic: 10
3081
3159
 
3082
3160
  - [toml](#plugins-toml) (provides `load_from_toml`, `save_to_toml`, `expose_toml`);
3083
3161
  - [pretty_print](#plugins-pretty_print) (beautified/prettified console output);
3162
+ - [vault](#plugins-vault) (provides `load_from_vault`, `expose_vault`)
3084
3163
 
3085
3164
  ---
3086
3165
 
@@ -3204,15 +3283,52 @@ config = Config.new
3204
3283
 
3205
3284
  ---
3206
3285
 
3286
+ ### Plugins: vault
3287
+
3288
+ - `Qonfig.plugin(:vault)`
3289
+ - adds support for `vault kv store`, [more info](https://www.vaultproject.io/docs/secrets/kv/kv-v2)
3290
+ - depends on `vault` gem ([link](https://github.com/hashicorp/vault-ruby)) (tested on `>= 0.1`);
3291
+ - provides `.load_from_vault` (works in `.load_from_yaml` manner ([doc](#load-from-yaml-file)));
3292
+ - provides `.expose_vault` (works in `.expose_yaml` manner ([doc](#expose-yaml)));
3293
+
3294
+ ```ruby
3295
+ # 1) require external dependency
3296
+ require 'vault'
3297
+
3298
+ # 2) Setup vault client
3299
+
3300
+ Vault.address = 'http://localhost:8200'
3301
+ Vault.token = 'super-duper-token-here'
3302
+
3303
+ # 3) enable plugin
3304
+ Qonfig.plugin(:vault)
3305
+
3306
+ # 3) use vault :)
3307
+ ```
3308
+
3309
+ ---
3310
+
3207
3311
  ## Roadmap
3208
3312
 
3209
3313
  - **Major**:
3210
- - distributed configuration server;
3211
- - cli toolchain;
3212
3314
  - support for Rails-like secrets;
3213
3315
  - support for persistent data storages (we want to store configs in multiple databases and files);
3214
- - Rails reload plugin;
3316
+ - rails plugin;
3317
+ - support for pattern matching;
3318
+ - support for type checking (via `rbs`, `typeprof`, `steep`);
3215
3319
  - **Minor**:
3320
+ - An ability to flag `Qonfig::Configurable`'s config object as `compacted` (`Qonfig::Compacted`);
3321
+ - Instance-based behavior for `Vault` plugin, also use instance of `Vault` client instead of `Singleton`;
3322
+ - External validation class with an importing api for better custom validations;
3323
+ - Setting value changement trace (in `anyway_config` manner);
3324
+ - Instantiation and reloading callbacks;
3325
+
3326
+ ## Build
3327
+
3328
+ ```shell
3329
+ bin/rspec -w # test the core functionality and plugins
3330
+ bin/rspec -n # test only the core functionality
3331
+ ```
3216
3332
 
3217
3333
  ## Contributing
3218
3334