config 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a73b8d9d0d0b87e7663d494adcef7051ea4df4d6ab7a0e501ae096c870d0220
4
- data.tar.gz: f97f4226c7baa682647f3098317526a45c3e8d45bbbde48e80e7b3183e090736
3
+ metadata.gz: 9e61b3780ec9c2a5586d1e50691a655761542740ed0ae370b5c1ad769e4d6349
4
+ data.tar.gz: 9a3d32e7943894f2f44546ab8c161d8b97ffe3a6df620856cbb037c337d83db6
5
5
  SHA512:
6
- metadata.gz: 28248c7da97c294525d04d56b5e470c171231d15bcb7bbff3029adc5b2710e00e9ebf07ea0697bbb9b2444a64d8f25a1e0a3e7492cda727bf4a84b2a8f936712
7
- data.tar.gz: 36462bd11b537212ee25d6d05c90297f65ccb4db4a7b80657f2b6c3647ff8ded75de3b8649672bad4a77b6947e17709efc875404c2a2f5126b5b7fb9a4cd0ab9
6
+ metadata.gz: 58015736b2f1bd3394102de9dcf09c64ee9f56c51abac9673a1a38dd867ab26b12abccda26c0b81d04c052a9e6c8cff48fd015004734dc4f9a0abb1dec1a1dea
7
+ data.tar.gz: cfea04abd4b76cd40913dea8544df5a049ecaf50faa475fe3662f6b3389bdf9aac35c26d9614dbaaf35df06ee7033ae4ee6a3943bc28373583cd930c9569b186
@@ -2,7 +2,23 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ...
5
+ ## 2.1.0
6
+
7
+ ### New features
8
+
9
+ * Add dry-validation contract support ([#238](https://github.com/railsconfig/config/pull/238))
10
+
11
+ ### Changes
12
+
13
+ * Get rid of activesupport dependency ([#230](https://github.com/railsconfig/config/pull/230))
14
+ * Ignore .local files in test environment ([#135](https://github.com/railsconfig/config/issues/135), [#233](https://github.com/railsconfig/config/pull/233))
15
+ * Execute default rspec against latest Rails app and load appropriate development dependencies dynamically ([#241](https://github.com/railsconfig/config/pull/241))
16
+ * Fix inconsistent documentation for ENV prefix and default value in generator ([#246](https://github.com/railsconfig/config/pull/246))
17
+
18
+ ### Bug fixes
19
+
20
+ * Fix warnings when running tests in Rails 5 scope ([#240](https://github.com/railsconfig/config/issues/240)
21
+ * Do not run incompatible code coverage on truffleruby ([#242](https://github.com/railsconfig/config/issues/242)
6
22
 
7
23
  ## 2.0.0
8
24
 
@@ -0,0 +1,32 @@
1
+ # Contributing
2
+
3
+ Install appraisal
4
+
5
+ ```bash
6
+ gem install bundler -v 1.17.3
7
+ gem install appraisal
8
+ ```
9
+
10
+ Bundle
11
+
12
+ ```bash
13
+ bundle install
14
+ ```
15
+
16
+ Bootstrap
17
+
18
+ ```bash
19
+ appraisal install
20
+ ```
21
+
22
+ Run the test suite:
23
+
24
+ ```bash
25
+ appraisal rspec
26
+ ```
27
+
28
+ If you modified any of the documentation files verify their format:
29
+
30
+ ```bash
31
+ mdl --style .mdlstyle.rb *.md
32
+ ```
data/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/config.svg)](http://badge.fury.io/rb/config)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/maintainability)](https://codeclimate.com/github/railsconfig/config/maintainability)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/test_coverage)](https://codeclimate.com/github/railsconfig/config/test_coverage)
7
+ [![Financial Contributors on Open Collective](https://opencollective.com/rubyconfig/all/badge.svg?label=financial+contributors)](https://opencollective.com/rubyconfig)
7
8
 
8
9
  ## Summary
9
10
 
@@ -57,8 +58,7 @@ register Config
57
58
 
58
59
  ### Installing on Sinatra
59
60
 
60
- Add the gem to your `Gemfile` and run `bundle install` to install it. Afterwards in need to register `Config` in your
61
- app and give it a root so it can find the config files.
61
+ Add the gem to your `Gemfile` and run `bundle install` to install it. Afterwards in need to register `Config` in your app and give it a root so it can find the config files.
62
62
 
63
63
  ```ruby
64
64
  set :root, File.dirname(__FILE__)
@@ -67,15 +67,13 @@ register Config
67
67
 
68
68
  ### Installing on other ruby projects
69
69
 
70
- Add the gem to your `Gemfile` and run `bundle install` to install it.
71
- Then initialize `Config` manually within your configure block.
70
+ Add the gem to your `Gemfile` and run `bundle install` to install it. Then initialize `Config` manually within your configure block.
72
71
 
73
72
  ```ruby
74
73
  Config.load_and_set_settings(Config.setting_files("/path/to/config_root", "your_project_environment"))
75
74
  ```
76
75
 
77
- It's also possible to initialize `Config` manually within your configure block if you want to just give it some yml
78
- paths to load from.
76
+ It's also possible to initialize `Config` manually within your configure block if you want to just give it some yml paths to load from.
79
77
 
80
78
  ```ruby
81
79
  Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
@@ -83,8 +81,7 @@ Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
83
81
 
84
82
  ## Accessing the Settings object
85
83
 
86
- After installing the gem, `Settings` object will become available globally and by default will be compiled from the
87
- files listed below. Settings defined in files that are lower in the list override settings higher.
84
+ After installing the gem, `Settings` object will become available globally and by default will be compiled from the files listed below. Settings defined in files that are lower in the list override settings higher.
88
85
 
89
86
  config/settings.yml
90
87
  config/settings/#{environment}.yml
@@ -136,8 +133,7 @@ Settings.reload_from_files(
136
133
 
137
134
  ### Environment specific config files
138
135
 
139
- You can have environment specific config files. Environment specific config entries take precedence over common config
140
- entries.
136
+ You can have environment specific config files. Environment specific config entries take precedence over common config entries.
141
137
 
142
138
  Example development environment config file:
143
139
 
@@ -153,8 +149,7 @@ Example production environment config file:
153
149
 
154
150
  ### Developer specific config files
155
151
 
156
- If you want to have local settings, specific to your machine or development environment,
157
- you can use the following files, which are automatically `.gitignore` :
152
+ If you want to have local settings, specific to your machine or development environment, you can use the following files, which are automatically `.gitignore` :
158
153
 
159
154
  ```ruby
160
155
  Rails.root.join("config", "settings.local.yml").to_s,
@@ -162,6 +157,8 @@ Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
162
157
  Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
163
158
  ```
164
159
 
160
+ **NOTE:** The file `settings.local.yml` will not be loaded in tests to prevent local configuration from causing flaky or non-deterministic tests. Environment-specific files (e.g. `settings/test.local.yml`) will still be loaded to allow test-specific credentials.
161
+
165
162
  ### Adding sources at runtime
166
163
 
167
164
  You can add new YAML config files at runtime. Just use:
@@ -180,11 +177,9 @@ Settings.prepend_source!("/path/to/source.yml")
180
177
  Settings.reload!
181
178
  ```
182
179
 
183
- This will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings
184
- will be overwritten by any other configuration file. This is especially useful if you want to define defaults.
180
+ This will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings will be overwritten by any other configuration file. This is especially useful if you want to define defaults.
185
181
 
186
- One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent
187
- per developer). Then I create a new initializer in `config/initializers/add_local_config.rb` with the contents
182
+ One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent per developer). Then I create a new initializer in `config/initializers/add_local_config.rb` with the contents
188
183
 
189
184
  ```ruby
190
185
  Settings.add_source!("#{Rails.root}/config/settings/local.yml")
@@ -252,18 +247,16 @@ Settings.section.servers[1].name # => amazon.com
252
247
 
253
248
  ## Configuration
254
249
 
255
- There are multiple configuration options available, however you can customize `Config` only once, preferably during
256
- application initialization phase:
250
+ There are multiple configuration options available, however you can customize `Config` only once, preferably during application initialization phase:
257
251
 
258
252
  ```ruby
259
253
  Config.setup do |config|
260
254
  config.const_name = 'Settings'
261
- ...
255
+ # ...
262
256
  end
263
257
  ```
264
258
 
265
- After installing `Config` in Rails, you will find automatically generated file that contains default configuration
266
- located at `config/initializers/config.rb`.
259
+ After installing `Config` in Rails, you will find automatically generated file that contains default configuration located at `config/initializers/config.rb`.
267
260
 
268
261
  ### General
269
262
 
@@ -300,12 +293,52 @@ Check [Deep Merge](https://github.com/danielsdeleo/deep_merge) for more details.
300
293
 
301
294
  ### Validation
302
295
 
303
- With Ruby 2.1 or newer, you can optionally define a schema to validate presence (and type) of specific config values:
296
+ With Ruby 2.1 or newer, you can optionally define a [schema](https://github.com/dry-rb/dry-schema) or [contract](https://github.com/dry-rb/dry-validation) (added in `config-2.1`) using [dry-rb](https://github.com/dry-rb) to validate presence (and type) of specific config values. Generally speaking contracts allow to describe more complex validations with depencecies between fields.
297
+
298
+ If you provide either validation option (or both) it will automatically be used to validate your config. If validation fails it will raise a `Config::Validation::Error` containing information about all the mismatches between the schema and your config.
299
+
300
+ Both examples below demonstrates how to ensure that the configuration has an optional `email` and the `youtube` structure with the `api_key` field filled. The contract adds an additional rule.
301
+
302
+ #### Contract
303
+
304
+ Leverage dry-validation, you can create a contract with a params schema and rules:
305
+
306
+ ```ruby
307
+ class ConfigContract < Dry::Validation::Contract
308
+ params do
309
+ optional(:email).maybe(:str?)
310
+
311
+ required(:youtube).schema do
312
+ required(:api_key).filled
313
+ end
314
+ end
315
+
316
+ rule(:email) do
317
+ unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
318
+ key.failure('has invalid format')
319
+ end
320
+ end
321
+ end
322
+
323
+ Config.setup do |config|
324
+ config.validation_contract = ConfigContract
325
+ end
326
+ ```
327
+
328
+ The above example adds a rule to ensure the `email` is valid by matching it against the provided regular expression.
329
+
330
+ Check [dry-validation](https://github.com/dry-rb/dry-validation) for more details.
331
+
332
+ #### Schema
333
+
334
+ You may also specify a schema using [dry-schema](https://github.com/dry-rb/dry-schema):
304
335
 
305
336
  ```ruby
306
337
  Config.setup do |config|
307
338
  # ...
308
339
  config.schema do
340
+ optional(:email).maybe(:str?)
341
+
309
342
  required(:youtube).schema do
310
343
  required(:api_key).filled
311
344
  end
@@ -313,13 +346,6 @@ Config.setup do |config|
313
346
  end
314
347
  ```
315
348
 
316
- The above example demonstrates how to ensure that the configuration has the `youtube` structure
317
- with the `api_key` field filled.
318
-
319
- If you define a schema it will automatically be used to validate your config. If validation fails it will
320
- raise a `Config::Validation::Error` containing a nice message with information about all the mismatches
321
- between the schema and your config.
322
-
323
349
  Check [dry-schema](https://github.com/dry-rb/dry-schema) for more details.
324
350
 
325
351
  ### Missing keys
@@ -371,8 +397,7 @@ See section below for more details.
371
397
 
372
398
  ## Working with environment variables
373
399
 
374
- To load environment variables from the `ENV` object, that will override any settings defined in files, set the `use_env`
375
- to true in your `config/initializers/config.rb` file:
400
+ To load environment variables from the `ENV` object, that will override any settings defined in files, set the `use_env` to true in your `config/initializers/config.rb` file:
376
401
 
377
402
  ```ruby
378
403
  Config.setup do |config|
@@ -381,8 +406,7 @@ Config.setup do |config|
381
406
  end
382
407
  ```
383
408
 
384
- Now config would read values from the ENV object to the settings. For the example above it would look for keys starting
385
- with `Settings`:
409
+ Now config would read values from the ENV object to the settings. For the example above it would look for keys starting with `Settings`:
386
410
 
387
411
  ```ruby
388
412
  ENV['Settings.section.size'] = 1
@@ -393,9 +417,7 @@ It won't work with arrays, though.
393
417
 
394
418
  ### Working with Heroku
395
419
 
396
- Heroku uses ENV object to store sensitive settings. You cannot upload such files to Heroku because it's ephemeral
397
- filesystem gets recreated from the git sources on each instance refresh. To use config with Heroku just set the
398
- `use_env` var to `true` as mentioned above.
420
+ Heroku uses ENV object to store sensitive settings. You cannot upload such files to Heroku because it's ephemeral filesystem gets recreated from the git sources on each instance refresh. To use config with Heroku just set the `use_env` var to `true` as mentioned above.
399
421
 
400
422
  To upload your local values to Heroku you could ran `bundle exec rake config:heroku`.
401
423
 
@@ -403,10 +425,8 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her
403
425
 
404
426
  You can customize how environment variables are processed:
405
427
 
406
- * `env_prefix` (default: `SETTINGS`) - which ENV variables to load into config
407
- * `env_separator` (default: `.`) - what string to use as level separator - default value of `.` works well with
408
- Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using
409
- dots in variable names might not be allowed (eg. Bash)
428
+ * `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive)
429
+ * `env_separator` (default: `'.'`) - what string to use as level separator - default value of `.` works well with Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using dots in variable names might not be allowed (eg. Bash)
410
430
  * `env_converter` (default: `:downcase`) - how to process variables names:
411
431
  * `nil` - no change
412
432
  * `:downcase` - convert to lower case
@@ -442,30 +462,11 @@ Settings.section.ssl_enabled # => false
442
462
 
443
463
  ## Contributing
444
464
 
445
- Install appraisal
465
+ You are very warmly welcome to help. Please follow our [contribution guidelines](CONTRIBUTING.md)
446
466
 
447
- ```bash
448
- gem install bundler -v 1.17.3
449
- gem install appraisal
450
- ```
467
+ Any and all contributions offered in any form, past present or future are understood to be in complete agreement and acceptance with [MIT](LICENSE) license.
451
468
 
452
- Bootstrap
453
469
 
454
- ```bash
455
- appraisal install
456
- ```
457
-
458
- Run the test suite:
459
-
460
- ```bash
461
- appraisal rspec
462
- ```
463
-
464
- If you modified any of the documentation files verify their format:
465
-
466
- ```bash
467
- mdl --style .mdlstyle.rb *.md
468
- ```
469
470
 
470
471
  ## Authors
471
472
 
@@ -474,6 +475,36 @@ mdl --style .mdlstyle.rb *.md
474
475
  * [Jacques Crocker](http://github.com/railsjedi)
475
476
  * Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
476
477
 
478
+ ## Contributors
479
+
480
+ ### Code Contributors
481
+
482
+ This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
483
+ <a href="https://github.com/railsconfig/config/graphs/contributors"><img src="https://opencollective.com/rubyconfig/contributors.svg?width=890&button=false" /></a>
484
+
485
+ ### Financial Contributors
486
+
487
+ [[Become a financial contributor](https://opencollective.com/rubyconfig/contribute)] and and support us with a small donation to help us continue our activities. Thank you if you already one! 🙏
488
+
489
+ #### Individuals
490
+
491
+ <a href="https://opencollective.com/rubyconfig"><img src="https://opencollective.com/rubyconfig/individuals.svg?width=890"></a>
492
+
493
+ #### Organizations
494
+
495
+ Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/rubyconfig/contribute)]
496
+
497
+ <a href="https://opencollective.com/rubyconfig/organization/0/website"><img src="https://opencollective.com/rubyconfig/organization/0/avatar.svg"></a>
498
+ <a href="https://opencollective.com/rubyconfig/organization/1/website"><img src="https://opencollective.com/rubyconfig/organization/1/avatar.svg"></a>
499
+ <a href="https://opencollective.com/rubyconfig/organization/2/website"><img src="https://opencollective.com/rubyconfig/organization/2/avatar.svg"></a>
500
+ <a href="https://opencollective.com/rubyconfig/organization/3/website"><img src="https://opencollective.com/rubyconfig/organization/3/avatar.svg"></a>
501
+ <a href="https://opencollective.com/rubyconfig/organization/4/website"><img src="https://opencollective.com/rubyconfig/organization/4/avatar.svg"></a>
502
+ <a href="https://opencollective.com/rubyconfig/organization/5/website"><img src="https://opencollective.com/rubyconfig/organization/5/avatar.svg"></a>
503
+ <a href="https://opencollective.com/rubyconfig/organization/6/website"><img src="https://opencollective.com/rubyconfig/organization/6/avatar.svg"></a>
504
+ <a href="https://opencollective.com/rubyconfig/organization/7/website"><img src="https://opencollective.com/rubyconfig/organization/7/avatar.svg"></a>
505
+ <a href="https://opencollective.com/rubyconfig/organization/8/website"><img src="https://opencollective.com/rubyconfig/organization/8/avatar.svg"></a>
506
+ <a href="https://opencollective.com/rubyconfig/organization/9/website"><img src="https://opencollective.com/rubyconfig/organization/9/avatar.svg"></a>
507
+
477
508
  ## License
478
509
 
479
510
  Config is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -7,14 +7,18 @@ Gem::Specification.new do |s|
7
7
  s.version = Config::VERSION
8
8
  s.date = Time.now.strftime '%F'
9
9
  s.authors = ['Piotr Kuczynski', 'Fred Wu', 'Jacques Crocker']
10
- s.email = %w(piotr.kuczynski@gmail.com ifredwu@gmail.com railsjedi@gmail.com)
10
+ s.email = %w[piotr.kuczynski@gmail.com ifredwu@gmail.com railsjedi@gmail.com]
11
11
  s.summary = 'Effortless multi-environment settings in Rails, Sinatra, Pandrino and others'
12
12
  s.description = 'Easiest way to manage multi-environment settings in any ruby project or framework: ' +
13
13
  'Rails, Sinatra, Pandrino and others'
14
14
  s.homepage = 'https://github.com/railsconfig/config'
15
15
  s.license = 'MIT'
16
- s.extra_rdoc_files = %w(README.md CHANGELOG.md LICENSE.md)
16
+ s.extra_rdoc_files = %w[README.md CHANGELOG.md CONTRIBUTING.md LICENSE.md]
17
17
  s.rdoc_options = ['--charset=UTF-8']
18
+ s.post_install_message = "\n\e[33mThanks for installing Config\e[0m 🙏
19
+ Please consider donating to our open collective to help us maintain this project.
20
+ \n
21
+ 👉 Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
18
22
 
19
23
  s.files = `git ls-files`.split($/)
20
24
  s.files.select! { |file| /(^lib\/|\.md$|\.gemspec$)/ =~ file }
@@ -23,27 +27,29 @@ Gem::Specification.new do |s|
23
27
  s.require_paths = ['lib']
24
28
  s.required_ruby_version = '>= 2.4.0'
25
29
 
26
- s.add_dependency 'activesupport', '>= 4.2'
27
30
  s.add_dependency 'deep_merge', '~> 1.2', '>= 1.2.1'
28
- s.add_dependency 'dry-schema', '~> 1.0'
31
+ s.add_dependency 'dry-validation', '~> 1.0'
29
32
 
30
- s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
33
+ s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
31
34
 
32
35
  # Testing
33
- s.add_development_dependency 'appraisal', '~> 2.2', '>= 2.2.0'
34
- s.add_development_dependency 'rails', '~> 5.2', '>= 5.2.2'
35
- s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
36
- s.add_development_dependency 'rspec-rails', '~> 3.7', '>= 3.7.2'
37
- s.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.7'
38
- s.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.13'
36
+ s.add_development_dependency 'appraisal', '~> 2.2', '>= 2.2.0'
37
+ s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
38
+
39
+ # Default RSpec run will test against latest Rails app
40
+ unless ENV['APPRAISAL_INITIALIZED']
41
+ File.read(Dir['gemfiles/rails*.gemfile'].sort.last).scan(/gem "(.*?)", "(.*?)"/m) do |name, version|
42
+ s.add_development_dependency name, version
43
+ end
44
+ end
39
45
 
40
46
  # Static code analysis
41
- s.add_development_dependency 'mdl', '~> 0.5', '>= 0.5.0'
47
+ s.add_development_dependency 'mdl', '~> 0.5', '>= 0.5.0'
42
48
 
43
49
  # Version 0.62 requires Ruby 2.2
44
- s.add_development_dependency 'rubocop', '~> 0.62'
50
+ s.add_development_dependency 'rubocop', '~> 0.62'
45
51
 
46
- if ENV['TRAVIS']
52
+ if ENV['TRAVIS'] && ENV['TRAVIS_RUBY_VERSION'] != 'truffleruby'
47
53
  s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.9'
48
54
  s.add_development_dependency 'simplecov', '~> 0.13.0'
49
55
  end
@@ -1,7 +1,7 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
-
1
+ require 'dry-validation'
3
2
  require 'config/compatibility'
4
3
  require 'config/options'
4
+ require 'config/configuration'
5
5
  require 'config/version'
6
6
  require 'config/integrations/rails/engine' if defined?(::Rails)
7
7
  require 'config/sources/yaml_source'
@@ -11,30 +11,26 @@ require 'deep_merge'
11
11
 
12
12
  module Config
13
13
  extend Config::Validation::Schema
14
-
15
- # Ensures the setup only gets run once
16
- @@_ran_once = false
17
-
18
- mattr_accessor :const_name, :use_env, :env_prefix, :env_separator,
19
- :env_converter, :env_parse_values, :fail_on_missing
20
- @@const_name = 'Settings'
21
- @@use_env = false
22
- @@env_prefix = @@const_name
23
- @@env_separator = '.'
24
- @@env_converter = :downcase
25
- @@env_parse_values = true
26
- @@fail_on_missing = false
27
-
28
- # deep_merge options
29
- mattr_accessor :knockout_prefix, :merge_nil_values, :overwrite_arrays, :merge_hash_arrays
30
- @@knockout_prefix = nil
31
- @@merge_nil_values = true
32
- @@overwrite_arrays = true
33
- @@merge_hash_arrays = false
14
+ extend Config::Configuration.new(
15
+ # general options
16
+ const_name: 'Settings',
17
+ use_env: false,
18
+ env_prefix: 'Settings',
19
+ env_separator: '.',
20
+ env_converter: :downcase,
21
+ env_parse_values: true,
22
+ fail_on_missing: false,
23
+ # deep_merge options
24
+ knockout_prefix: nil,
25
+ merge_nil_values: true,
26
+ overwrite_arrays: true,
27
+ merge_hash_arrays: false,
28
+ validation_contract: nil
29
+ )
34
30
 
35
31
  def self.setup
36
- yield self if @@_ran_once == false
37
- @@_ran_once = true
32
+ yield self unless @_ran_once
33
+ @_ran_once = true
38
34
  end
39
35
 
40
36
  # Create a populated Options instance from a settings file. If a second file is given, then the sections of that
@@ -48,7 +44,7 @@ module Config
48
44
  end
49
45
 
50
46
  config.load!
51
- config.load_env! if @@use_env
47
+ config.load_env! if use_env
52
48
  config
53
49
  end
54
50
 
@@ -61,16 +57,21 @@ module Config
61
57
 
62
58
  def self.setting_files(config_root, env)
63
59
  [
64
- File.join(config_root, "settings.yml").to_s,
65
- File.join(config_root, "settings", "#{env}.yml").to_s,
66
- File.join(config_root, "environments", "#{env}.yml").to_s,
67
-
68
- File.join(config_root, "settings.local.yml").to_s,
69
- File.join(config_root, "settings", "#{env}.local.yml").to_s,
70
- File.join(config_root, "environments", "#{env}.local.yml").to_s
60
+ File.join(config_root, 'settings.yml').to_s,
61
+ File.join(config_root, 'settings', "#{env}.yml").to_s,
62
+ File.join(config_root, 'environments', "#{env}.yml").to_s,
63
+ *local_setting_files(config_root, env)
71
64
  ].freeze
72
65
  end
73
66
 
67
+ def self.local_setting_files(config_root, env)
68
+ [
69
+ (File.join(config_root, 'settings.local.yml').to_s if env != 'test'),
70
+ File.join(config_root, 'settings', "#{env}.local.yml").to_s,
71
+ File.join(config_root, 'environments', "#{env}.local.yml").to_s
72
+ ].compact
73
+ end
74
+
74
75
  def self.reload!
75
76
  Object.const_get(Config.const_name).reload!
76
77
  end
@@ -0,0 +1,36 @@
1
+ module Config
2
+ # The main configuration backbone
3
+ class Configuration < Module
4
+ # Accepts configuration options,
5
+ # initializing a module that can be used to extend
6
+ # the necessary class with the provided config methods
7
+ def initialize(**attributes)
8
+ attributes.each do |name, default|
9
+ define_reader(name, default)
10
+ define_writer(name)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def define_reader(name, default)
17
+ variable = :"@#{name}"
18
+
19
+ define_method(name) do
20
+ if instance_variable_defined?(variable)
21
+ instance_variable_get(variable)
22
+ else
23
+ default
24
+ end
25
+ end
26
+ end
27
+
28
+ def define_writer(name)
29
+ variable = :"@#{name}"
30
+
31
+ define_method("#{name}=") do |value|
32
+ instance_variable_set(variable, value)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -143,7 +143,7 @@ module Config
143
143
  end
144
144
 
145
145
  # Some keywords that don't play nicely with OpenStruct
146
- SETTINGS_RESERVED_NAMES = %w[select collect test count zip].freeze
146
+ SETTINGS_RESERVED_NAMES = %w[select collect test count zip min max].freeze
147
147
 
148
148
  # An alternative mechanism for property access.
149
149
  # This let's you do foo['bar'] along with foo.bar.
@@ -1,21 +1,18 @@
1
- require 'dry-schema'
2
- require 'config/validation/schema'
3
-
4
1
  module Config
5
2
  module Validation
6
3
  module Schema
7
-
8
- mattr_writer :schema
9
- @@schema = nil
4
+ # Assigns schema configuration option
5
+ def schema=(value)
6
+ @schema = value
7
+ end
10
8
 
11
9
  def schema(&block)
12
10
  if block_given?
13
- @@schema = Dry::Schema.define(&block)
11
+ @schema = Dry::Schema.define(&block)
14
12
  else
15
- @@schema
13
+ @schema
16
14
  end
17
15
  end
18
-
19
16
  end
20
17
  end
21
18
  end
@@ -3,18 +3,23 @@ require 'config/validation/error'
3
3
  module Config
4
4
  module Validation
5
5
  module Validate
6
-
7
6
  def validate!
8
- if Config.schema
9
- v_res = Config.schema.(self.to_hash)
7
+ validate_using!(Config.validation_contract)
8
+ validate_using!(Config.schema)
9
+ end
10
+
11
+ private
10
12
 
11
- unless v_res.success?
12
- error = Config::Validation::Error.format(v_res)
13
- raise Config::Validation::Error.new("Config validation failed:\n\n#{error}")
14
- end
13
+ def validate_using!(validator)
14
+ if validator
15
+ result = validator.call(to_hash)
16
+
17
+ return if result.success?
18
+
19
+ error = Config::Validation::Error.format(result)
20
+ raise Config::Validation::Error, "Config validation failed:\n\n#{error}"
15
21
  end
16
22
  end
17
-
18
23
  end
19
24
  end
20
25
  end
@@ -1,3 +1,3 @@
1
1
  module Config
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.0'.freeze
3
3
  end
@@ -21,7 +21,12 @@ Config.setup do |config|
21
21
 
22
22
  # Define ENV variable prefix deciding which variables to load into config.
23
23
  #
24
- # config.env_prefix = 'Settings'
24
+ # Reading variables from ENV is case-sensitive. If you define lowercase value below, ensure your ENV variables are
25
+ # prefixed in the same way.
26
+ #
27
+ # When not set it defaults to `config.const_name`.
28
+ #
29
+ config.env_prefix = 'SETTINGS'
25
30
 
26
31
  # What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
27
32
  # with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kuczynski
@@ -10,22 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-06-22 00:00:00.000000000 Z
13
+ date: 2020-01-03 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: activesupport
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: '4.2'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: '4.2'
29
15
  - !ruby/object:Gem::Dependency
30
16
  name: deep_merge
31
17
  requirement: !ruby/object:Gem::Requirement
@@ -47,7 +33,7 @@ dependencies:
47
33
  - !ruby/object:Gem::Version
48
34
  version: 1.2.1
49
35
  - !ruby/object:Gem::Dependency
50
- name: dry-schema
36
+ name: dry-validation
51
37
  requirement: !ruby/object:Gem::Requirement
52
38
  requirements:
53
39
  - - "~>"
@@ -100,26 +86,6 @@ dependencies:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
88
  version: '2.2'
103
- - !ruby/object:Gem::Dependency
104
- name: rails
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '5.2'
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 5.2.2
113
- type: :development
114
- prerelease: false
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '5.2'
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: 5.2.2
123
89
  - !ruby/object:Gem::Dependency
124
90
  name: rspec
125
91
  requirement: !ruby/object:Gem::Requirement
@@ -141,65 +107,61 @@ dependencies:
141
107
  - !ruby/object:Gem::Version
142
108
  version: '3.7'
143
109
  - !ruby/object:Gem::Dependency
144
- name: rspec-rails
110
+ name: bootsnap
145
111
  requirement: !ruby/object:Gem::Requirement
146
112
  requirements:
147
113
  - - "~>"
148
114
  - !ruby/object:Gem::Version
149
- version: '3.7'
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: 3.7.2
115
+ version: '1.4'
153
116
  type: :development
154
117
  prerelease: false
155
118
  version_requirements: !ruby/object:Gem::Requirement
156
119
  requirements:
157
120
  - - "~>"
158
121
  - !ruby/object:Gem::Version
159
- version: '3.7'
160
- - - ">="
122
+ version: '1.4'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rails
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '='
128
+ - !ruby/object:Gem::Version
129
+ version: 5.2.2
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '='
161
135
  - !ruby/object:Gem::Version
162
- version: 3.7.2
136
+ version: 5.2.2
163
137
  - !ruby/object:Gem::Dependency
164
- name: test-unit
138
+ name: rspec-rails
165
139
  requirement: !ruby/object:Gem::Requirement
166
140
  requirements:
167
141
  - - "~>"
168
142
  - !ruby/object:Gem::Version
169
- version: '3.2'
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- version: 3.2.7
143
+ version: '3.7'
173
144
  type: :development
174
145
  prerelease: false
175
146
  version_requirements: !ruby/object:Gem::Requirement
176
147
  requirements:
177
148
  - - "~>"
178
149
  - !ruby/object:Gem::Version
179
- version: '3.2'
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- version: 3.2.7
150
+ version: '3.7'
183
151
  - !ruby/object:Gem::Dependency
184
152
  name: sqlite3
185
153
  requirement: !ruby/object:Gem::Requirement
186
154
  requirements:
187
- - - "~>"
188
- - !ruby/object:Gem::Version
189
- version: '1.3'
190
- - - ">="
155
+ - - "<"
191
156
  - !ruby/object:Gem::Version
192
- version: 1.3.13
157
+ version: 1.4.0
193
158
  type: :development
194
159
  prerelease: false
195
160
  version_requirements: !ruby/object:Gem::Requirement
196
161
  requirements:
197
- - - "~>"
198
- - !ruby/object:Gem::Version
199
- version: '1.3'
200
- - - ">="
162
+ - - "<"
201
163
  - !ruby/object:Gem::Version
202
- version: 1.3.13
164
+ version: 1.4.0
203
165
  - !ruby/object:Gem::Dependency
204
166
  name: mdl
205
167
  requirement: !ruby/object:Gem::Requirement
@@ -245,14 +207,17 @@ extensions: []
245
207
  extra_rdoc_files:
246
208
  - README.md
247
209
  - CHANGELOG.md
210
+ - CONTRIBUTING.md
248
211
  - LICENSE.md
249
212
  files:
250
213
  - CHANGELOG.md
214
+ - CONTRIBUTING.md
251
215
  - LICENSE.md
252
216
  - README.md
253
217
  - config.gemspec
254
218
  - lib/config.rb
255
219
  - lib/config/compatibility.rb
220
+ - lib/config/configuration.rb
256
221
  - lib/config/integrations/heroku.rb
257
222
  - lib/config/integrations/rails/engine.rb
258
223
  - lib/config/integrations/rails/railtie.rb
@@ -273,14 +238,16 @@ files:
273
238
  - lib/generators/config/templates/settings/development.yml
274
239
  - lib/generators/config/templates/settings/production.yml
275
240
  - lib/generators/config/templates/settings/test.yml
241
+ - spec/app/rails_5.0/README.md
276
242
  - spec/app/rails_5.1/README.md
277
243
  - spec/app/rails_5.2/README.md
278
- - spec/app/rails_5/README.md
279
244
  homepage: https://github.com/railsconfig/config
280
245
  licenses:
281
246
  - MIT
282
247
  metadata: {}
283
- post_install_message:
248
+ post_install_message: "\n\e[33mThanks for installing Config\e[0m \U0001F64F\nPlease
249
+ consider donating to our open collective to help us maintain this project.\n\n\n\U0001F449
250
+ \ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
284
251
  rdoc_options:
285
252
  - "--charset=UTF-8"
286
253
  require_paths: