confset 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +44 -0
  3. data/docs/CHANGELOG.md +15 -0
  4. data/docs/LICENSE.md +29 -0
  5. data/lib/confset/configuration.rb +37 -0
  6. data/lib/confset/integrations/heroku.rb +61 -0
  7. data/lib/confset/integrations/rails/railtie.rb +40 -0
  8. data/lib/confset/integrations/sinatra.rb +27 -0
  9. data/lib/confset/options.rb +187 -0
  10. data/lib/confset/rack/reloader.rb +17 -0
  11. data/lib/confset/sources/env_source.rb +74 -0
  12. data/lib/confset/sources/hash_source.rb +18 -0
  13. data/lib/confset/sources/yaml_source.rb +34 -0
  14. data/lib/confset/tasks/heroku.rake +9 -0
  15. data/lib/confset/validation/error.rb +13 -0
  16. data/lib/confset/validation/schema.rb +22 -0
  17. data/lib/confset/validation/validate.rb +26 -0
  18. data/lib/confset/version.rb +5 -0
  19. data/lib/confset.rb +89 -0
  20. data/lib/generators/confset/install_generator.rb +34 -0
  21. data/lib/generators/confset/templates/confset.rb +58 -0
  22. data/lib/generators/confset/templates/settings/development.yml +0 -0
  23. data/lib/generators/confset/templates/settings/production.yml +0 -0
  24. data/lib/generators/confset/templates/settings/test.yml +0 -0
  25. data/lib/generators/confset/templates/settings.local.yml +0 -0
  26. data/lib/generators/confset/templates/settings.yml +0 -0
  27. data/spec/config_env_spec.rb +238 -0
  28. data/spec/config_spec.rb +468 -0
  29. data/spec/configuration_spec.rb +16 -0
  30. data/spec/fixtures/bool_override/config1.yml +2 -0
  31. data/spec/fixtures/bool_override/config2.yml +2 -0
  32. data/spec/fixtures/custom_types/hash.yml +7 -0
  33. data/spec/fixtures/deep_merge/config1.yml +31 -0
  34. data/spec/fixtures/deep_merge/config2.yml +28 -0
  35. data/spec/fixtures/deep_merge2/config1.yml +3 -0
  36. data/spec/fixtures/deep_merge2/config2.yml +2 -0
  37. data/spec/fixtures/deep_merge3/config1.yml +1 -0
  38. data/spec/fixtures/deep_merge3/config2.yml +1 -0
  39. data/spec/fixtures/development.yml +4 -0
  40. data/spec/fixtures/empty1.yml +0 -0
  41. data/spec/fixtures/empty2.yml +0 -0
  42. data/spec/fixtures/knockout_prefix/config1.yml +40 -0
  43. data/spec/fixtures/knockout_prefix/config2.yml +28 -0
  44. data/spec/fixtures/knockout_prefix/config3.yml +14 -0
  45. data/spec/fixtures/malformed.yml +6 -0
  46. data/spec/fixtures/multilevel.yml +10 -0
  47. data/spec/fixtures/overwrite_arrays/config1.yml +17 -0
  48. data/spec/fixtures/overwrite_arrays/config2.yml +12 -0
  49. data/spec/fixtures/overwrite_arrays/config3.yml +10 -0
  50. data/spec/fixtures/reserved_keywords.yml +7 -0
  51. data/spec/fixtures/settings.yml +22 -0
  52. data/spec/fixtures/settings2.yml +1 -0
  53. data/spec/fixtures/unsafe_load.yml +12 -0
  54. data/spec/fixtures/validation/confset.yml +3 -0
  55. data/spec/fixtures/with_erb.yml +4 -0
  56. data/spec/fixtures/with_malformed_erb.yml +1 -0
  57. data/spec/options_spec.rb +255 -0
  58. data/spec/sources/env_source_spec.rb +81 -0
  59. data/spec/sources/hash_source_spec.rb +49 -0
  60. data/spec/sources/yaml_source_spec.rb +145 -0
  61. data/spec/spec_helper.rb +28 -0
  62. data/spec/support/fixture_helper.rb +14 -0
  63. data/spec/support/rails_helper.rb +24 -0
  64. data/spec/support/shared_contexts/rake.rb +8 -0
  65. data/spec/validation_spec.rb +84 -0
  66. metadata +295 -0
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # Confset Rspec Helpers
5
+ #
6
+
7
+ # Loads ENV vars from a yaml file
8
+ def load_env(filename)
9
+ if filename && File.exist?(filename.to_s)
10
+ result = YAML.load(ERB.new(IO.read(filename.to_s)).result)
11
+ end
12
+ result.each { |key, value| ENV[key.to_s] = value.to_s } unless result.nil?
13
+ end
14
+
15
+ # Checks if (default) Confset const is already available
16
+ def config_available?
17
+ where = caller[0].split(":")[0].gsub(File.expand_path(File.dirname(__FILE__)), "")
18
+
19
+ if defined?(::Settings)
20
+ puts "Confset available in #{where}"
21
+ else
22
+ raise "Confset not available in #{where}"
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_context "rake" do
4
+ # include rails rake tasks
5
+ before do
6
+ require "rake"
7
+ end
8
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "dry-validation"
5
+
6
+ describe Confset do
7
+ context "validation" do
8
+ around(:each) do |example|
9
+ Confset.reset
10
+ example.run
11
+ Confset.reset
12
+ end
13
+
14
+ context "with validation_contract" do
15
+ it "should raise if validation_contract is present and validation fails" do
16
+ contract = Class.new(Dry::Validation::Contract)
17
+ contract.params do
18
+ required(:youtube).schema do
19
+ required(:nonexist_field).filled
20
+ required(:multiple_requirements).filled(:integer, gt?: 18)
21
+ end
22
+ end
23
+ Confset.setup do |config|
24
+ config.validation_contract = contract.new
25
+ end
26
+
27
+ msg = "Confset validation failed:\n\n"
28
+ msg += " youtube.nonexist_field: is missing\n"
29
+ msg += " youtube.multiple_requirements: must be an integer"
30
+
31
+ expect { Confset.load_files("spec/fixtures/validation/confset.yml") }.
32
+ to raise_error(Confset::Validation::Error, Regexp.new(msg))
33
+ end
34
+
35
+ it "should work if validation passes" do
36
+ contract = Class.new(Dry::Validation::Contract)
37
+ contract.params do
38
+ required(:youtube).schema do
39
+ required(:api_key).filled
40
+ end
41
+ end
42
+ Confset.setup do |config|
43
+ config.validation_contract = contract.new
44
+ end
45
+
46
+ expect { Confset.load_files("spec/fixtures/validation/confset.yml") }.
47
+ to_not raise_error
48
+ end
49
+ end
50
+
51
+ context "with schema" do
52
+ it "should raise if schema is present and validation fails" do
53
+ Confset.setup do |config|
54
+ config.schema do
55
+ required(:youtube).schema do
56
+ required(:nonexist_field).filled
57
+ required(:multiple_requirements).filled(:integer, gt?: 18)
58
+ end
59
+ end
60
+ end
61
+
62
+ msg = "Confset validation failed:\n\n"
63
+ msg += " youtube.nonexist_field: is missing\n"
64
+ msg += " youtube.multiple_requirements: must be an integer"
65
+
66
+ expect { Confset.load_files("spec/fixtures/validation/confset.yml") }.
67
+ to raise_error(Confset::Validation::Error, Regexp.new(msg))
68
+ end
69
+
70
+ it "should work if validation passes" do
71
+ Confset.setup do |config|
72
+ config.schema do
73
+ required(:youtube).schema do
74
+ required(:api_key).filled
75
+ end
76
+ end
77
+ end
78
+
79
+ expect { Confset.load_files("spec/fixtures/validation/confset.yml") }.
80
+ to_not raise_error
81
+ end
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,295 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: confset
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Danilo Carolino
8
+ - Piotr Kuczynski
9
+ - Fred Wu
10
+ - Jacques Crocker
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2022-05-27 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: deep_merge
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.2'
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.2.1
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.2'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.2.1
36
+ - !ruby/object:Gem::Dependency
37
+ name: dry-validation
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.0.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.9'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.9.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.9'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.9.0
76
+ - !ruby/object:Gem::Dependency
77
+ name: rake
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: simplecov
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.21'
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.21'
104
+ - !ruby/object:Gem::Dependency
105
+ name: mdl
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.11'
118
+ - !ruby/object:Gem::Dependency
119
+ name: rubocop
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.29'
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.29'
132
+ - !ruby/object:Gem::Dependency
133
+ name: rubocop-packaging
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.5'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.5'
146
+ - !ruby/object:Gem::Dependency
147
+ name: rubocop-performance
148
+ requirement: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.14'
153
+ type: :development
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.14'
160
+ description: 'Easiest way to manage multi-environment settings in any ruby project
161
+ or framework: '
162
+ email:
163
+ - danilogcarolino@gmail.com
164
+ executables: []
165
+ extensions: []
166
+ extra_rdoc_files: []
167
+ files:
168
+ - Rakefile
169
+ - docs/CHANGELOG.md
170
+ - docs/LICENSE.md
171
+ - lib/confset.rb
172
+ - lib/confset/configuration.rb
173
+ - lib/confset/integrations/heroku.rb
174
+ - lib/confset/integrations/rails/railtie.rb
175
+ - lib/confset/integrations/sinatra.rb
176
+ - lib/confset/options.rb
177
+ - lib/confset/rack/reloader.rb
178
+ - lib/confset/sources/env_source.rb
179
+ - lib/confset/sources/hash_source.rb
180
+ - lib/confset/sources/yaml_source.rb
181
+ - lib/confset/tasks/heroku.rake
182
+ - lib/confset/validation/error.rb
183
+ - lib/confset/validation/schema.rb
184
+ - lib/confset/validation/validate.rb
185
+ - lib/confset/version.rb
186
+ - lib/generators/confset/install_generator.rb
187
+ - lib/generators/confset/templates/confset.rb
188
+ - lib/generators/confset/templates/settings.local.yml
189
+ - lib/generators/confset/templates/settings.yml
190
+ - lib/generators/confset/templates/settings/development.yml
191
+ - lib/generators/confset/templates/settings/production.yml
192
+ - lib/generators/confset/templates/settings/test.yml
193
+ - spec/config_env_spec.rb
194
+ - spec/config_spec.rb
195
+ - spec/configuration_spec.rb
196
+ - spec/fixtures/bool_override/config1.yml
197
+ - spec/fixtures/bool_override/config2.yml
198
+ - spec/fixtures/custom_types/hash.yml
199
+ - spec/fixtures/deep_merge/config1.yml
200
+ - spec/fixtures/deep_merge/config2.yml
201
+ - spec/fixtures/deep_merge2/config1.yml
202
+ - spec/fixtures/deep_merge2/config2.yml
203
+ - spec/fixtures/deep_merge3/config1.yml
204
+ - spec/fixtures/deep_merge3/config2.yml
205
+ - spec/fixtures/development.yml
206
+ - spec/fixtures/empty1.yml
207
+ - spec/fixtures/empty2.yml
208
+ - spec/fixtures/knockout_prefix/config1.yml
209
+ - spec/fixtures/knockout_prefix/config2.yml
210
+ - spec/fixtures/knockout_prefix/config3.yml
211
+ - spec/fixtures/malformed.yml
212
+ - spec/fixtures/multilevel.yml
213
+ - spec/fixtures/overwrite_arrays/config1.yml
214
+ - spec/fixtures/overwrite_arrays/config2.yml
215
+ - spec/fixtures/overwrite_arrays/config3.yml
216
+ - spec/fixtures/reserved_keywords.yml
217
+ - spec/fixtures/settings.yml
218
+ - spec/fixtures/settings2.yml
219
+ - spec/fixtures/unsafe_load.yml
220
+ - spec/fixtures/validation/confset.yml
221
+ - spec/fixtures/with_erb.yml
222
+ - spec/fixtures/with_malformed_erb.yml
223
+ - spec/options_spec.rb
224
+ - spec/sources/env_source_spec.rb
225
+ - spec/sources/hash_source_spec.rb
226
+ - spec/sources/yaml_source_spec.rb
227
+ - spec/spec_helper.rb
228
+ - spec/support/fixture_helper.rb
229
+ - spec/support/rails_helper.rb
230
+ - spec/support/shared_contexts/rake.rb
231
+ - spec/validation_spec.rb
232
+ homepage: https://github.com/dcotecnologia/confset
233
+ licenses:
234
+ - MIT
235
+ metadata: {}
236
+ post_install_message:
237
+ rdoc_options:
238
+ - "--charset=UTF-8"
239
+ require_paths:
240
+ - lib
241
+ required_ruby_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: 2.7.0
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements: []
252
+ rubygems_version: 3.3.7
253
+ signing_key:
254
+ specification_version: 4
255
+ summary: Effortless multi-environment settings in Rails, Sinatra, Pandrino and others
256
+ test_files:
257
+ - spec/config_env_spec.rb
258
+ - spec/config_spec.rb
259
+ - spec/configuration_spec.rb
260
+ - spec/fixtures/bool_override/config1.yml
261
+ - spec/fixtures/bool_override/config2.yml
262
+ - spec/fixtures/custom_types/hash.yml
263
+ - spec/fixtures/deep_merge/config1.yml
264
+ - spec/fixtures/deep_merge/config2.yml
265
+ - spec/fixtures/deep_merge2/config1.yml
266
+ - spec/fixtures/deep_merge2/config2.yml
267
+ - spec/fixtures/deep_merge3/config1.yml
268
+ - spec/fixtures/deep_merge3/config2.yml
269
+ - spec/fixtures/development.yml
270
+ - spec/fixtures/empty1.yml
271
+ - spec/fixtures/empty2.yml
272
+ - spec/fixtures/knockout_prefix/config1.yml
273
+ - spec/fixtures/knockout_prefix/config2.yml
274
+ - spec/fixtures/knockout_prefix/config3.yml
275
+ - spec/fixtures/malformed.yml
276
+ - spec/fixtures/multilevel.yml
277
+ - spec/fixtures/overwrite_arrays/config1.yml
278
+ - spec/fixtures/overwrite_arrays/config2.yml
279
+ - spec/fixtures/overwrite_arrays/config3.yml
280
+ - spec/fixtures/reserved_keywords.yml
281
+ - spec/fixtures/settings.yml
282
+ - spec/fixtures/settings2.yml
283
+ - spec/fixtures/unsafe_load.yml
284
+ - spec/fixtures/validation/confset.yml
285
+ - spec/fixtures/with_erb.yml
286
+ - spec/fixtures/with_malformed_erb.yml
287
+ - spec/options_spec.rb
288
+ - spec/sources/env_source_spec.rb
289
+ - spec/sources/hash_source_spec.rb
290
+ - spec/sources/yaml_source_spec.rb
291
+ - spec/spec_helper.rb
292
+ - spec/support/fixture_helper.rb
293
+ - spec/support/rails_helper.rb
294
+ - spec/support/shared_contexts/rake.rb
295
+ - spec/validation_spec.rb