qonfig 0.25.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 (136) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.rubocop.yml +19 -1
  4. data/.travis.yml +7 -2
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile.lock +102 -0
  7. data/README.md +2 -0
  8. data/gemfiles/with_external_deps.gemfile.lock +112 -0
  9. data/gemfiles/without_external_deps.gemfile.lock +102 -0
  10. data/lib/qonfig.rb +1 -1
  11. data/lib/qonfig/commands/definition/load_from_env.rb +2 -0
  12. data/lib/qonfig/commands/definition/load_from_env/value_converter.rb +2 -0
  13. data/lib/qonfig/imports/direct_key.rb +8 -2
  14. data/lib/qonfig/imports/mappings.rb +8 -2
  15. data/lib/qonfig/loaders/basic.rb +2 -0
  16. data/lib/qonfig/loaders/json.rb +2 -1
  17. data/lib/qonfig/settings.rb +5 -1
  18. data/lib/qonfig/settings/key_matcher.rb +1 -1
  19. data/lib/qonfig/uploaders/base.rb +2 -0
  20. data/lib/qonfig/uploaders/yaml.rb +2 -0
  21. data/lib/qonfig/version.rb +1 -1
  22. data/qonfig.gemspec +4 -6
  23. data/sig/.keep +0 -0
  24. data/spec/features/clear_options_spec.rb +92 -0
  25. data/spec/features/compacted_config_spec.rb +308 -0
  26. data/spec/features/composition_spec.rb +207 -0
  27. data/spec/features/config_definition_and_representation_spec.rb +535 -0
  28. data/spec/features/definition_order_spec.rb +69 -0
  29. data/spec/features/dig_functionality_spec.rb +47 -0
  30. data/spec/features/dot_notation_spec.rb +159 -0
  31. data/spec/features/export_settings_spec.rb +138 -0
  32. data/spec/features/expose_json_spec.rb +281 -0
  33. data/spec/features/expose_self/format_option_dynamic_spec.rb +69 -0
  34. data/spec/features/expose_self/format_option_json_spec.rb +74 -0
  35. data/spec/features/expose_self/format_option_unsupported_spec.rb +27 -0
  36. data/spec/features/expose_self/format_option_yaml_spec.rb +77 -0
  37. data/spec/features/expose_self_spec.rb +97 -0
  38. data/spec/features/expose_yaml_spec.rb +263 -0
  39. data/spec/features/freeze_state_spec.rb +122 -0
  40. data/spec/features/get_config_keys_spec.rb +62 -0
  41. data/spec/features/get_config_values_spec.rb +41 -0
  42. data/spec/features/has_a_key_spec.rb +48 -0
  43. data/spec/features/import_settings_spec.rb +323 -0
  44. data/spec/features/indifferent_access_spec.rb +57 -0
  45. data/spec/features/inheritance_spec.rb +110 -0
  46. data/spec/features/instantiation_without_class_definition_spec.rb +59 -0
  47. data/spec/features/iteration_over_setting_keys_spec.rb +48 -0
  48. data/spec/features/load_from_env_spec.rb +240 -0
  49. data/spec/features/load_from_json_spec.rb +97 -0
  50. data/spec/features/load_from_self/format_option_json_spec.rb +31 -0
  51. data/spec/features/load_from_self/format_option_unsupported_spec.rb +27 -0
  52. data/spec/features/load_from_self/format_option_yaml_spec.rb +49 -0
  53. data/spec/features/load_from_self/with_erb_instructions_spec.rb +33 -0
  54. data/spec/features/load_from_self/with_hash_like_data_representation_spec.rb +66 -0
  55. data/spec/features/load_from_self/with_non_hash_like_data_representation_spec.rb +19 -0
  56. data/spec/features/load_from_self/without_end_data_spec.rb +11 -0
  57. data/spec/features/load_from_yaml_spec.rb +110 -0
  58. data/spec/features/load_setting_values_from_file/by_instance_method_examples.rb +171 -0
  59. data/spec/features/load_setting_values_from_file/by_macros_examples.rb +165 -0
  60. data/spec/features/load_setting_values_from_file/load_from_json_spec.rb +21 -0
  61. data/spec/features/load_setting_values_from_file/load_from_self/json_format/end_data_with_env_spec.rb +100 -0
  62. data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_end_data_spec.rb +129 -0
  63. data/spec/features/load_setting_values_from_file/load_from_self/json_format/with_incorrect_end_data_spec.rb +34 -0
  64. data/spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb +65 -0
  65. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/end_data_with_env_spec.rb +94 -0
  66. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_end_data_spec.rb +126 -0
  67. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/with_incorrect_end_data_spec.rb +32 -0
  68. data/spec/features/load_setting_values_from_file/load_from_self/yaml_format/without_end_data_spec.rb +65 -0
  69. data/spec/features/load_setting_values_from_file/load_from_yaml_spec.rb +21 -0
  70. data/spec/features/load_setting_values_from_file/shared_behavior_spec.rb +33 -0
  71. data/spec/features/mixin_spec.rb +387 -0
  72. data/spec/features/non_redefineable_core_methods_spec.rb +29 -0
  73. data/spec/features/plugins/pretty_print_spec.rb +86 -0
  74. data/spec/features/plugins/toml/expose_self/format_option_toml_spec.rb +71 -0
  75. data/spec/features/plugins/toml/expose_toml_spec.rb +221 -0
  76. data/spec/features/plugins/toml/load_from_self/format_option_toml_spec.rb +27 -0
  77. data/spec/features/plugins/toml/load_from_toml_spec.rb +109 -0
  78. data/spec/features/plugins/toml/load_setting_values_from_file/load_from_toml_spec.rb +27 -0
  79. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/end_data_with_env_spec.rb +95 -0
  80. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_end_data_spec.rb +125 -0
  81. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/with_incorrect_end_data_spec.rb +34 -0
  82. data/spec/features/plugins/toml/load_setting_values_from_file/load_toml_from_self/without_end_data_spec.rb +65 -0
  83. data/spec/features/plugins/toml/load_setting_values_from_file/shared_behavior_spec.rb +34 -0
  84. data/spec/features/plugins/toml/save_to_toml_spec.rb +149 -0
  85. data/spec/features/plugins/vault/expose_vault_spec.rb +117 -0
  86. data/spec/features/plugins/vault/load_from_vault_spec.rb +80 -0
  87. data/spec/features/plugins_spec.rb +89 -0
  88. data/spec/features/reload_spec.rb +75 -0
  89. data/spec/features/run_code_with_temporary_settings_spec.rb +104 -0
  90. data/spec/features/save_to_file/save_to_json_spec.rb +157 -0
  91. data/spec/features/save_to_file/save_to_yaml_spec.rb +189 -0
  92. data/spec/features/settings_as_predicates_spec.rb +47 -0
  93. data/spec/features/settings_redefinition_spec.rb +30 -0
  94. data/spec/features/slice_functionality_spec.rb +69 -0
  95. data/spec/features/subset_functionality_spec.rb +49 -0
  96. data/spec/features/validation_spec.rb +916 -0
  97. data/spec/fixtures/array_settings.yml +3 -0
  98. data/spec/fixtures/expose_json/incompatible_root_structure.json +6 -0
  99. data/spec/fixtures/expose_json/incompatible_structure.json +4 -0
  100. data/spec/fixtures/expose_json/project.development.json +7 -0
  101. data/spec/fixtures/expose_json/project.json +30 -0
  102. data/spec/fixtures/expose_json/project.production.json +7 -0
  103. data/spec/fixtures/expose_json/project.staging.json +7 -0
  104. data/spec/fixtures/expose_json/project.test.json +7 -0
  105. data/spec/fixtures/expose_yaml/incompatible_structure.yml +2 -0
  106. data/spec/fixtures/expose_yaml/project.development.yml +4 -0
  107. data/spec/fixtures/expose_yaml/project.production.yml +4 -0
  108. data/spec/fixtures/expose_yaml/project.staging.yml +4 -0
  109. data/spec/fixtures/expose_yaml/project.test.yml +4 -0
  110. data/spec/fixtures/expose_yaml/project.yml +25 -0
  111. data/spec/fixtures/json_array_sample.json +14 -0
  112. data/spec/fixtures/json_object_sample.json +9 -0
  113. data/spec/fixtures/json_with_empty_object.json +6 -0
  114. data/spec/fixtures/json_with_erb.json +6 -0
  115. data/spec/fixtures/plugins/toml/expose_toml/project.development.toml +4 -0
  116. data/spec/fixtures/plugins/toml/expose_toml/project.production.toml +4 -0
  117. data/spec/fixtures/plugins/toml/expose_toml/project.staging.toml +4 -0
  118. data/spec/fixtures/plugins/toml/expose_toml/project.test.toml +4 -0
  119. data/spec/fixtures/plugins/toml/expose_toml/project.toml +27 -0
  120. data/spec/fixtures/plugins/toml/mini_file.toml +6 -0
  121. data/spec/fixtures/plugins/toml/toml_sample_with_all_types.toml +72 -0
  122. data/spec/fixtures/plugins/toml/values_file/with_env.toml +13 -0
  123. data/spec/fixtures/plugins/toml/values_file/without_env.toml +6 -0
  124. data/spec/fixtures/rubocop_settings.yml +12 -0
  125. data/spec/fixtures/shared_settings_with_aliases.yml +10 -0
  126. data/spec/fixtures/travis_settings.yml +6 -0
  127. data/spec/fixtures/values_file/with_env.json +19 -0
  128. data/spec/fixtures/values_file/with_env.yml +17 -0
  129. data/spec/fixtures/values_file/without_env.json +8 -0
  130. data/spec/fixtures/values_file/without_env.yml +5 -0
  131. data/spec/fixtures/with_empty_hash.yml +4 -0
  132. data/spec/fixtures/with_erb_instructions.yml +3 -0
  133. data/spec/spec_helper.rb +27 -0
  134. data/spec/support/meta_scopes.rb +20 -0
  135. data/spec/support/spec_support.rb +42 -0
  136. metadata +128 -11
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe '.values_file / #load_from_self (with incorrect __END__ data) (YAML format)' do
4
+ describe 'DSL macros' do
5
+ let(:config_klass) do
6
+ Class.new(Qonfig::DataSet) do
7
+ values_file :self, format: :yaml
8
+ setting :user, 'D@iVeR'
9
+ end
10
+ end
11
+
12
+ specify 'fails with corresponding error' do
13
+ expect { config_klass.new }.to raise_error(Qonfig::YAMLLoaderParseError)
14
+ end
15
+ end
16
+
17
+ describe 'Instance method' do
18
+ let(:config) do
19
+ Qonfig::DataSet.build { setting :user, 'D@iVeR' }
20
+ end
21
+
22
+ specify 'fails with corresponding error' do
23
+ expect { config.load_from_self(format: :yaml) }.to raise_error(Qonfig::YAMLLoaderParseError)
24
+ expect(config.settings.user).to eq('D@iVeR')
25
+ end
26
+ end
27
+ end
28
+
29
+ __END__
30
+
31
+ user: 0exp
32
+ ASDF|"asSDF"
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe '.values_file / #load_from_self (without __END__ data) (YAML format)' do
4
+ describe 'DSL macros' do
5
+ context 'strict behavior' do
6
+ let(:config_klass) do
7
+ Class.new(Qonfig::DataSet) do
8
+ values_file :self, format: :yaml, strict: true
9
+ setting :user, 'D@iVeR'
10
+ end
11
+ end
12
+
13
+ specify 'fails with Qonfig::SelfDataNotFoundError' do
14
+ expect { config_klass.new }.to raise_error(Qonfig::SelfDataNotFoundError)
15
+ end
16
+ end
17
+
18
+ context 'non-strict behavior (default)' do
19
+ let(:config_klass) do
20
+ Class.new(Qonfig::DataSet) do
21
+ values_file :self, format: :yaml
22
+ setting :user, 'D@iVeR'
23
+ end
24
+ end
25
+
26
+ specify 'config instantiation works well :)' do
27
+ config = nil
28
+ expect { config = config_klass.new }.not_to raise_error
29
+ expect(config.settings.user).to eq('D@iVeR')
30
+ end
31
+ end
32
+ end
33
+
34
+ describe 'Instance method' do
35
+ context 'strict behavior (default)' do
36
+ let(:config_klass) do
37
+ Class.new(Qonfig::DataSet) { setting :user, 'D@iVeR' }
38
+ end
39
+
40
+ specify 'fails with Qonfig::SelfDataNotFoundError' do
41
+ config = config_klass.new
42
+
43
+ expect do
44
+ config.load_from_self(format: :yaml, strict: true)
45
+ end.to raise_error(Qonfig::SelfDataNotFoundError)
46
+ end
47
+ end
48
+
49
+ context 'non-strict behavior' do
50
+ let(:config_klass) do
51
+ Class.new(Qonfig::DataSet) { setting :user, 'D@iVeR' }
52
+ end
53
+
54
+ specify 'no errors :)' do
55
+ config = config_klass.new
56
+
57
+ expect do
58
+ config.load_from_self(format: :yaml, strict: false)
59
+ end.not_to raise_error
60
+
61
+ expect(config.settings.user).to eq('D@iVeR')
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'by_macros_examples'
4
+ require_relative 'by_instance_method_examples'
5
+
6
+ describe 'Load setting values from YAML file' do
7
+ describe 'DSL macros (Qonfig::DataSet.values_file)' do
8
+ it_behaves_like 'load setting values from file by macros',
9
+ file_name: SpecSupport.fixture_path('values_file', 'without_env.yml'),
10
+ file_with_env_name: SpecSupport.fixture_path('values_file', 'with_env.yml'),
11
+ file_format: :yaml
12
+ end
13
+
14
+ describe 'Instance methods (Qonfig::DataSet#load_from_file/.load_from_yaml' do
15
+ it_behaves_like 'load setting values from file by instance methods',
16
+ file_name: SpecSupport.fixture_path('values_file', 'without_env.yml'),
17
+ file_with_env_name: SpecSupport.fixture_path('values_file', 'with_env.yml'),
18
+ load_by: :load_from_yaml,
19
+ file_format: :yaml
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe '.values_file / #load_from_file (shared behavior)' do
4
+ describe 'unsupported format failures' do
5
+ describe 'DSL macros' do
6
+ specify 'fails on unsupported format' do
7
+ expect do
8
+ Qonfig::DataSet.build do
9
+ values_file :self
10
+ end
11
+ end.to raise_error(Qonfig::DynamicLoaderParseError)
12
+ end
13
+ end
14
+
15
+ describe 'Instance method' do
16
+ specify 'fails on unsupported format' do
17
+ expect do
18
+ Qonfig::DataSet.build.load_from_self
19
+ end.to raise_error(Qonfig::DynamicLoaderParseError)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ __END__
26
+
27
+ user: 0exp
28
+ ASDF|"asSDF"
29
+ <xml>
30
+ <data>
31
+ <key>123</key>
32
+ </data>
33
+ </xml>
@@ -0,0 +1,387 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe 'Mixin (Qonfig::Configurable)' do
4
+ ENV['QONFIG_MIXIN_GENERIC_VARIABLE'] = 'true'
5
+
6
+ class AnyApplication
7
+ include Qonfig::Configurable
8
+
9
+ configuration do
10
+ setting :env do
11
+ load_from_env convert_values: true, prefix: 'QONFIG_MIXIN_', trim_prefix: true
12
+ end
13
+
14
+ setting :data do
15
+ load_from_self
16
+ end
17
+ end
18
+ end
19
+
20
+ class InheritedApplication < AnyApplication
21
+ configuration do
22
+ setting :database do
23
+ setting :adapter, 'postgresql'
24
+ end
25
+ end
26
+ end
27
+
28
+ specify 'configurable class+instance level behaviour with working inheritance' do
29
+ any_app = AnyApplication.new
30
+
31
+ # class has it's own config object
32
+ expect(AnyApplication.config[:env][:GENERIC_VARIABLE]).to eq(true)
33
+ expect(AnyApplication.config[:data][:version]).to eq(RUBY_VERSION)
34
+ expect(AnyApplication.config[:data][:language]).to eq('ruby')
35
+
36
+ # instance has it's own config object
37
+ expect(any_app.config[:env][:GENERIC_VARIABLE]).to eq(true)
38
+ expect(any_app.config[:data][:version]).to eq(RUBY_VERSION)
39
+ expect(any_app.config[:data][:language]).to eq('ruby')
40
+
41
+ # instance has an access to the class-level config
42
+ expect(any_app.shared_config).to eq(AnyApplication.config)
43
+ expect(any_app.shared_config[:env][:GENERIC_VARIABLE]).to eq(true)
44
+ expect(any_app.shared_config[:data][:version]).to eq(RUBY_VERSION)
45
+ expect(any_app.shared_config[:data][:language]).to eq('ruby')
46
+
47
+ # configure class-level config object
48
+ AnyApplication.configure do |conf|
49
+ conf.data.version = '9.2.0.0'
50
+ conf.data.language = 'jruby'
51
+ conf[:env][:GENERIC_VARIABLE] = false
52
+ end
53
+
54
+ # class config - affected
55
+ expect(AnyApplication.config[:env][:GENERIC_VARIABLE]).to eq(false)
56
+ expect(AnyApplication.config[:data][:version]).to eq('9.2.0.0')
57
+ expect(AnyApplication.config[:data][:language]).to eq('jruby')
58
+
59
+ # instance config - not affected
60
+ expect(any_app.config[:env][:GENERIC_VARIABLE]).to eq(true)
61
+ expect(any_app.config[:data][:version]).to eq(RUBY_VERSION)
62
+ expect(any_app.config[:data][:language]).to eq('ruby')
63
+
64
+ # instance has an access to the class-level config
65
+ expect(any_app.shared_config).to eq(AnyApplication.config)
66
+ expect(any_app.shared_config[:env][:GENERIC_VARIABLE]).to eq(false)
67
+ expect(any_app.shared_config[:data][:version]).to eq('9.2.0.0')
68
+ expect(any_app.shared_config[:data][:language]).to eq('jruby')
69
+
70
+ # configure instance-level config object
71
+ any_app.configure do |conf|
72
+ conf.data.version = '2.4.1'
73
+ conf.data.language = 'mruby'
74
+ conf[:env][:GENERIC_VARIABLE] = nil
75
+ end
76
+
77
+ # class config - not affected
78
+ expect(AnyApplication.config[:env][:GENERIC_VARIABLE]).to eq(false)
79
+ expect(AnyApplication.config[:data][:version]).to eq('9.2.0.0')
80
+ expect(AnyApplication.config[:data][:language]).to eq('jruby')
81
+
82
+ # instance config - affected
83
+ expect(any_app.config[:env][:GENERIC_VARIABLE]).to eq(nil)
84
+ expect(any_app.config[:data][:version]).to eq('2.4.1')
85
+ expect(any_app.config[:data][:language]).to eq('mruby')
86
+
87
+ # instance has an access to the class-level config
88
+ expect(any_app.shared_config).to eq(AnyApplication.config)
89
+ expect(any_app.shared_config[:env][:GENERIC_VARIABLE]).to eq(false)
90
+ expect(any_app.shared_config[:data][:version]).to eq('9.2.0.0')
91
+ expect(any_app.shared_config[:data][:language]).to eq('jruby')
92
+
93
+ # --- same with inhertiance ---
94
+
95
+ # inherited instance
96
+ inh_app = InheritedApplication.new
97
+
98
+ # class has it's own config object
99
+ expect(InheritedApplication.config[:env][:GENERIC_VARIABLE]).to eq(true)
100
+ expect(InheritedApplication.config[:data][:version]).to eq(RUBY_VERSION)
101
+ expect(InheritedApplication.config[:data][:language]).to eq('ruby')
102
+ expect(InheritedApplication.config[:database][:adapter]).to eq('postgresql')
103
+
104
+ # instance has it's own config object
105
+ expect(inh_app.config[:env][:GENERIC_VARIABLE]).to eq(true)
106
+ expect(inh_app.config[:data][:version]).to eq(RUBY_VERSION)
107
+ expect(inh_app.config[:data][:language]).to eq('ruby')
108
+ expect(inh_app.config[:database][:adapter]).to eq('postgresql')
109
+
110
+ # instance has an access to the class-level config
111
+ expect(inh_app.shared_config).to eq(InheritedApplication.config)
112
+ expect(inh_app.shared_config[:env][:GENERIC_VARIABLE]).to eq(true)
113
+ expect(inh_app.shared_config[:data][:version]).to eq(RUBY_VERSION)
114
+ expect(inh_app.shared_config[:data][:language]).to eq('ruby')
115
+ expect(inh_app.shared_config[:database][:adapter]).to eq('postgresql')
116
+
117
+ # configure class-level config object
118
+ InheritedApplication.configure do |conf|
119
+ conf[:env][:GENERIC_VARIABLE] = '123'
120
+ conf[:data][:version] = '2.2.10'
121
+ conf[:data][:language] = 'super_ruby'
122
+ conf[:database][:adapter] = 'oracle'
123
+ end
124
+
125
+ # class config - affected
126
+ expect(InheritedApplication.config[:env][:GENERIC_VARIABLE]).to eq('123')
127
+ expect(InheritedApplication.config[:data][:version]).to eq('2.2.10')
128
+ expect(InheritedApplication.config[:data][:language]).to eq('super_ruby')
129
+ expect(InheritedApplication.config[:database][:adapter]).to eq('oracle')
130
+
131
+ # instance config - not affected
132
+ expect(inh_app.config[:env][:GENERIC_VARIABLE]).to eq(true)
133
+ expect(inh_app.config[:data][:version]).to eq(RUBY_VERSION)
134
+ expect(inh_app.config[:data][:language]).to eq('ruby')
135
+ expect(inh_app.config[:database][:adapter]).to eq('postgresql')
136
+
137
+ # instance has an access to the class-level config
138
+ expect(inh_app.shared_config).to eq(InheritedApplication.config)
139
+ expect(inh_app.shared_config[:env][:GENERIC_VARIABLE]).to eq('123')
140
+ expect(inh_app.shared_config[:data][:version]).to eq('2.2.10')
141
+ expect(inh_app.shared_config[:data][:language]).to eq('super_ruby')
142
+ expect(inh_app.shared_config[:database][:adapter]).to eq('oracle')
143
+
144
+ # configure instance-level config object
145
+ inh_app.configure do |conf|
146
+ conf[:env][:GENERIC_VARIABLE] = 'mega-blast'
147
+ conf[:data][:version] = '3x3'
148
+ conf[:data][:language] = 'ultimate_ruby'
149
+ conf[:database][:adapter] = 'mongodb'
150
+ end
151
+
152
+ # class config - not affected
153
+ expect(InheritedApplication.config[:env][:GENERIC_VARIABLE]).to eq('123')
154
+ expect(InheritedApplication.config[:data][:version]).to eq('2.2.10')
155
+ expect(InheritedApplication.config[:data][:language]).to eq('super_ruby')
156
+ expect(InheritedApplication.config[:database][:adapter]).to eq('oracle')
157
+
158
+ # instance config - affected
159
+ expect(inh_app.config[:env][:GENERIC_VARIABLE]).to eq('mega-blast')
160
+ expect(inh_app.config[:data][:version]).to eq('3x3')
161
+ expect(inh_app.config[:data][:language]).to eq('ultimate_ruby')
162
+ expect(inh_app.config[:database][:adapter]).to eq('mongodb')
163
+
164
+ # instance has an access to the class-level config
165
+ expect(inh_app.shared_config).to eq(InheritedApplication.config)
166
+ expect(inh_app.shared_config[:env][:GENERIC_VARIABLE]).to eq('123')
167
+ expect(inh_app.shared_config[:data][:version]).to eq('2.2.10')
168
+ expect(inh_app.shared_config[:data][:language]).to eq('super_ruby')
169
+ expect(inh_app.shared_config[:database][:adapter]).to eq('oracle')
170
+
171
+ # -- there are no intersections between original and inherited entities --
172
+ expect(any_app.config.to_h).to match(
173
+ 'env' => { 'GENERIC_VARIABLE' => nil },
174
+ 'data' => { 'version' => '2.4.1', 'language' => 'mruby' }
175
+ )
176
+
177
+ expect(AnyApplication.config.to_h).to match(
178
+ 'env' => { 'GENERIC_VARIABLE' => false },
179
+ 'data' => { 'version' => '9.2.0.0', 'language' => 'jruby' }
180
+ )
181
+
182
+ expect(inh_app.config.to_h).to match(
183
+ 'env' => { 'GENERIC_VARIABLE' => 'mega-blast' },
184
+ 'data' => { 'version' => '3x3', 'language' => 'ultimate_ruby' },
185
+ 'database' => { 'adapter' => 'mongodb' }
186
+ )
187
+
188
+ expect(InheritedApplication.config.to_h).to match(
189
+ 'env' => { 'GENERIC_VARIABLE' => '123' },
190
+ 'data' => { 'version' => '2.2.10', 'language' => 'super_ruby' },
191
+ 'database' => { 'adapter' => 'oracle' }
192
+ )
193
+
194
+ # --- configuration with hash / hash + proc
195
+ AnyApplication.configure(env: { GENERIC_VARIABLE: false }) do |conf|
196
+ conf.data.version = '2.2.11'
197
+ conf.data.language = 'mega_ruby'
198
+ end
199
+ expect(AnyApplication.config.to_h).to match(
200
+ 'env' => { 'GENERIC_VARIABLE' => false },
201
+ 'data' => { 'version' => '2.2.11', 'language' => 'mega_ruby' }
202
+ )
203
+
204
+ any_app.configure(data: { version: '3x3' }) do |conf|
205
+ conf.data.language = 'ultra_ruby'
206
+ conf.env[:GENERIC_VARIABLE] = nil
207
+ end
208
+ expect(any_app.config.to_h).to match(
209
+ 'env' => { 'GENERIC_VARIABLE' => nil },
210
+ 'data' => { 'version' => '3x3', 'language' => 'ultra_ruby' }
211
+ )
212
+
213
+ [AnyApplication, any_app].each do |configurable|
214
+ expect do
215
+ configurable.configure(env: { nonexistent_key: 100 })
216
+ end.to raise_error(Qonfig::UnknownSettingError)
217
+ expect do
218
+ configurable.configure(nonexistent_key: false)
219
+ end.to raise_error(Qonfig::UnknownSettingError)
220
+ expect do
221
+ configurable.configure(env: nil)
222
+ end.to raise_error(Qonfig::AmbiguousSettingValueError)
223
+ end
224
+
225
+ # --- config definitions extend working correctly ---
226
+ AnyApplication.configuration do
227
+ setting :any_additional, 'any'
228
+ end
229
+
230
+ InheritedApplication.configuration do
231
+ setting :inh_additional, 'inh'
232
+ end
233
+
234
+ AnyApplication.config.reload!
235
+ any_app.config.reload!
236
+
237
+ InheritedApplication.config.reload!
238
+ inh_app.config.reload!
239
+
240
+ # instance has an access to the class-level config
241
+ expect(any_app.shared_config).to eq(AnyApplication.config)
242
+ expect(inh_app.shared_config).to eq(InheritedApplication.config)
243
+
244
+ expect(any_app.config.to_h).to match(
245
+ 'env' => { 'GENERIC_VARIABLE' => true },
246
+ 'data' => { 'version' => RUBY_VERSION, 'language' => 'ruby' },
247
+ 'any_additional' => 'any'
248
+ )
249
+
250
+ expect(AnyApplication.config.to_h).to match(
251
+ 'env' => { 'GENERIC_VARIABLE' => true },
252
+ 'data' => { 'version' => RUBY_VERSION, 'language' => 'ruby' },
253
+ 'any_additional' => 'any'
254
+ )
255
+
256
+ expect(any_app.shared_config.to_h).to match(
257
+ 'env' => { 'GENERIC_VARIABLE' => true },
258
+ 'data' => { 'version' => RUBY_VERSION, 'language' => 'ruby' },
259
+ 'any_additional' => 'any'
260
+ )
261
+
262
+ expect(inh_app.config.to_h).to match(
263
+ 'env' => { 'GENERIC_VARIABLE' => true },
264
+ 'data' => { 'version' => RUBY_VERSION, 'language' => 'ruby' },
265
+ 'database' => { 'adapter' => 'postgresql' },
266
+ 'inh_additional' => 'inh'
267
+ )
268
+
269
+ expect(InheritedApplication.config.to_h).to match(
270
+ 'env' => { 'GENERIC_VARIABLE' => true },
271
+ 'data' => { 'version' => RUBY_VERSION, 'language' => 'ruby' },
272
+ 'database' => { 'adapter' => 'postgresql' },
273
+ 'inh_additional' => 'inh'
274
+ )
275
+
276
+ expect(inh_app.shared_config.to_h).to match(
277
+ 'env' => { 'GENERIC_VARIABLE' => true },
278
+ 'data' => { 'version' => RUBY_VERSION, 'language' => 'ruby' },
279
+ 'database' => { 'adapter' => 'postgresql' },
280
+ 'inh_additional' => 'inh'
281
+ )
282
+
283
+ # --- #clear! works correctly ---
284
+ AnyApplication.config.clear!
285
+ any_app.config.clear!
286
+
287
+ InheritedApplication.config.clear!
288
+ inh_app.config.clear!
289
+
290
+ expect(any_app.config.to_h).to match(
291
+ 'env' => { 'GENERIC_VARIABLE' => nil },
292
+ 'data' => { 'version' => nil, 'language' => nil },
293
+ 'any_additional' => nil
294
+ )
295
+
296
+ expect(AnyApplication.config.to_h).to match(
297
+ 'env' => { 'GENERIC_VARIABLE' => nil },
298
+ 'data' => { 'version' => nil, 'language' => nil },
299
+ 'any_additional' => nil
300
+ )
301
+
302
+ expect(any_app.shared_config.to_h).to match(
303
+ 'env' => { 'GENERIC_VARIABLE' => nil },
304
+ 'data' => { 'version' => nil, 'language' => nil },
305
+ 'any_additional' => nil
306
+ )
307
+
308
+ expect(inh_app.config.to_h).to match(
309
+ 'env' => { 'GENERIC_VARIABLE' => nil },
310
+ 'data' => { 'version' => nil, 'language' => nil },
311
+ 'database' => { 'adapter' => nil },
312
+ 'inh_additional' => nil
313
+ )
314
+
315
+ expect(InheritedApplication.config.to_h).to match(
316
+ 'env' => { 'GENERIC_VARIABLE' => nil },
317
+ 'data' => { 'version' => nil, 'language' => nil },
318
+ 'database' => { 'adapter' => nil },
319
+ 'inh_additional' => nil
320
+ )
321
+
322
+ expect(inh_app.shared_config.to_h).to match(
323
+ 'env' => { 'GENERIC_VARIABLE' => nil },
324
+ 'data' => { 'version' => nil, 'language' => nil },
325
+ 'database' => { 'adapter' => nil },
326
+ 'inh_additional' => nil
327
+ )
328
+
329
+ # --- #freeze! does not intersects between class-level and instance-level configs ---
330
+ # --- #freeze! does not intersects between original and inherited entities ---
331
+
332
+ AnyApplication.config.freeze!
333
+ expect(any_app.shared_config).to eq(AnyApplication.config)
334
+
335
+ expect do
336
+ AnyApplication.configure { |conf| conf.any_additional = true }
337
+ end.to raise_error(Qonfig::FrozenSettingsError)
338
+
339
+ expect do
340
+ any_app.configure { |conf| conf.any_additional = true }
341
+ end.not_to raise_error
342
+
343
+ expect do
344
+ InheritedApplication.configure { |conf| conf.inh_additional = true }
345
+ end.not_to raise_error
346
+
347
+ expect do
348
+ inh_app.configure { |conf| conf.inh_additional = true }
349
+ end.not_to raise_error
350
+
351
+ any_app.config.freeze!
352
+
353
+ expect do
354
+ any_app.configure { |conf| conf.any_additional = true }
355
+ end.to raise_error(Qonfig::FrozenSettingsError)
356
+
357
+ expect do
358
+ InheritedApplication.configure { |conf| conf.inh_additional = true }
359
+ end.not_to raise_error
360
+
361
+ expect do
362
+ inh_app.configure { |conf| conf.inh_additional = true }
363
+ end.not_to raise_error
364
+
365
+ InheritedApplication.config.freeze!
366
+ expect(inh_app.shared_config).to eq(InheritedApplication.config)
367
+
368
+ expect do
369
+ InheritedApplication.configure { |conf| conf.inh_additional = true }
370
+ end.to raise_error(Qonfig::FrozenSettingsError)
371
+
372
+ expect do
373
+ inh_app.configure { |conf| conf.inh_additional = true }
374
+ end.not_to raise_error
375
+
376
+ inh_app.config.freeze!
377
+
378
+ expect do
379
+ inh_app.configure { |conf| conf.inh_additional = true }
380
+ end.to raise_error(Qonfig::FrozenSettingsError)
381
+ end
382
+ end
383
+
384
+ __END__
385
+
386
+ version: <%= RUBY_VERSION %>
387
+ language: ruby