config 2.0.0 → 3.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +116 -36
- data/CONTRIBUTING.md +32 -0
- data/README.md +149 -64
- data/config.gemspec +28 -24
- data/lib/config.rb +34 -33
- data/lib/config/configuration.rb +36 -0
- data/lib/config/integrations/rails/railtie.rb +1 -1
- data/lib/config/options.rb +8 -52
- data/lib/config/sources/env_source.rb +73 -0
- data/lib/config/validation/schema.rb +8 -9
- data/lib/config/validation/validate.rb +13 -8
- data/lib/config/version.rb +1 -1
- data/lib/generators/config/templates/config.rb +6 -1
- metadata +44 -89
- data/lib/config/integrations/rails/engine.rb +0 -9
- data/spec/app/rails_5.1/README.md +0 -24
- data/spec/app/rails_5.2/README.md +0 -24
- data/spec/app/rails_5/README.md +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9553d786b6f2a87d956e85494f9f8fd083e42076989e7c8217b84f72b1d6469
|
4
|
+
data.tar.gz: 592b1002dd18e793f444c2b4d00220c4cbbaf2f1e850d33c0d6c5bc5c41ae236
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c5e1c7de910d8f7592b0bf2d1ad322dbf8aa6565617ca1f5d0bdede78316073aa5afb5bf6e7cb33ce42bace7770f4cb8f8a86d4fd13a31fc0e900e58c6ae9c
|
7
|
+
data.tar.gz: 8fe4ecdb8069e910c36f68cb3a55863182797539638be36f7be622057174a45f4605427aaa0f145fd399a518131310059408812e9ff5dd391a1c7691b45624a7
|
data/CHANGELOG.md
CHANGED
@@ -4,111 +4,191 @@
|
|
4
4
|
|
5
5
|
...
|
6
6
|
|
7
|
+
## 3.0.0
|
8
|
+
|
9
|
+
### BREAKING CHANGES
|
10
|
+
|
11
|
+
* After upgrade behaviour of `to_h` would change and match behaviour of `to_hash`. Check [#217](https://github.com/rubyconfig/config/issues/217#issuecomment-741953382) for more details.
|
12
|
+
* `Config::Options#load_env!` and `Config::Options#reload_env!` have been removed. If you need to reload settings after modifying the `ENV` hash, use `Config.reload!` or `Config::Options#reload!` instead.
|
13
|
+
|
14
|
+
### Bug fixes
|
15
|
+
|
16
|
+
* Added alias `to_h` for `to_hash` ([#277](https://github.com/railsconfig/config/issues/277))
|
17
|
+
|
18
|
+
### Changes
|
19
|
+
|
20
|
+
* Add `Config::Sources::EnvSource` for loading settings from flat `Hash`es with `String` keys and `String` values ([#299](https://github.com/railsconfig/config/pull/299))
|
21
|
+
|
22
|
+
## 2.2.3
|
23
|
+
|
24
|
+
### Bug fixes
|
25
|
+
|
26
|
+
* Revert added alias to_h for to_hash ([#277](https://github.com/railsconfig/config/issues/277))
|
27
|
+
|
28
|
+
### Changes
|
29
|
+
|
30
|
+
* Raise explicit error on environment variable conflicts ([#293](https://github.com/railsconfig/config/issues/293))
|
31
|
+
|
32
|
+
## 2.2.2
|
33
|
+
|
34
|
+
### Bug fixes
|
35
|
+
|
36
|
+
* Added alias to_h for to_hash ([#277](https://github.com/railsconfig/config/issues/277))
|
37
|
+
* Prevent unnecessary doubled loading of environment variables ([#291](https://github.com/rubyconfig/config/pull/291))
|
38
|
+
* Return `Hash` from `Config::Options#as_json` instead of `Array` of pairs when using ActiveSupport Core Extensions ([#292](https://github.com/rubyconfig/config/pull/292))
|
39
|
+
|
40
|
+
### Changes
|
41
|
+
|
42
|
+
* Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228))
|
43
|
+
* Add exit! to reserved keywords ([#289](https://github.com/railsconfig/config/issues/289))
|
44
|
+
|
45
|
+
## 2.2.1
|
46
|
+
|
47
|
+
### Performance improvements
|
48
|
+
|
49
|
+
* Get rid of unused Rails Engine class definition ([#247](https://github.com/rubyconfig/config/pull/247))
|
50
|
+
* Require dry-validation only when schema is specified ([#253](https://github.com/rubyconfig/config/pull/253))
|
51
|
+
* Defer modification of `ActionController::Base` to when it is loaded in Rails integration ([#250](https://github.com/rubyconfig/config/pull/250))
|
52
|
+
|
53
|
+
### Bug fixes
|
54
|
+
|
55
|
+
* Fix missing new_ostruct_member in Ruby 2.7 ([#255](https://github.com/rubyconfig/config/pull/255))
|
56
|
+
* Fix validation contract documentation ([#260](https://github.com/rubyconfig/config/pull/260))
|
57
|
+
* Excluded test application's *.md files from the gem build ([#267](https://github.com/rubyconfig/config/pull/267))
|
58
|
+
|
59
|
+
### Changes
|
60
|
+
|
61
|
+
* Use sprockets 3.x when running unit tests for Rails 4.2 ([#256](https://github.com/rubyconfig/config/pull/256))
|
62
|
+
* Cleanup example Rails application used for testing ([#263](https://github.com/rubyconfig/config/pull/263))
|
63
|
+
* Upgrade markdown linter and fix errors ([#265](https://github.com/rubyconfig/config/pull/265))
|
64
|
+
* Upgrade development dependencies and test matrix with latest Ruby and Rails versions ([#264](https://github.com/rubyconfig/config/pull/264))
|
65
|
+
* Replace Travis CI with GitHub Actions ([#266](https://github.com/rubyconfig/config/pull/266))
|
66
|
+
* Add Rails 6.0 to the test matrix ([#258](https://github.com/rubyconfig/config/pull/258))
|
67
|
+
* Rename GitHub organization name from `railsconfig` to `rubyconfig` ([#268](https://github.com/rubyconfig/config/pull/268))
|
68
|
+
|
69
|
+
## 2.1.0
|
70
|
+
|
71
|
+
### New features
|
72
|
+
|
73
|
+
* Add dry-validation contract support ([#238](https://github.com/rubyconfig/config/pull/238))
|
74
|
+
|
75
|
+
### Changes
|
76
|
+
|
77
|
+
* Get rid of activesupport dependency ([#230](https://github.com/rubyconfig/config/pull/230))
|
78
|
+
* Ignore .local files in test environment ([#135](https://github.com/rubyconfig/config/issues/135), [#233](https://github.com/rubyconfig/config/pull/233))
|
79
|
+
* Execute default rspec against latest Rails app and load appropriate development dependencies dynamically ([#241](https://github.com/rubyconfig/config/pull/241))
|
80
|
+
* Fix inconsistent documentation for ENV prefix and default value in generator ([#246](https://github.com/rubyconfig/config/pull/246))
|
81
|
+
|
82
|
+
### Bug fixes
|
83
|
+
|
84
|
+
* Fix warnings when running tests in Rails 5 scope ([#240](https://github.com/rubyconfig/config/issues/240)
|
85
|
+
* Do not run incompatible code coverage on truffleruby ([#242](https://github.com/rubyconfig/config/issues/242)
|
86
|
+
|
7
87
|
## 2.0.0
|
8
88
|
|
9
89
|
### BREAKING CHANGES
|
10
90
|
|
11
91
|
After upgrade to dry-schema 1.0 we had to drop support for Rails `< 4.2` and Ruby `< 2.4`.
|
12
|
-
If you need older version of Ruby or Rails, please stick to 1.x version of this gem.
|
92
|
+
If you need older version of Ruby or Rails, please stick to 1.x version of this gem.
|
13
93
|
|
14
94
|
### New features
|
15
95
|
|
16
|
-
* Add `merge_hash_arrays` as a configuration option ([#214](https://github.com/
|
96
|
+
* Add `merge_hash_arrays` as a configuration option ([#214](https://github.com/rubyconfig/config/pull/214))
|
17
97
|
|
18
98
|
### Changes
|
19
99
|
|
20
|
-
* Upgraded dry-validation dependency to dry-schema 1.0 ([#224](https://github.com/
|
21
|
-
* Moved constant to be defined on `Object` instead of `Kernel` ([#227](https://github.com/
|
22
|
-
* Add TruffleRuby to the test matrix ([#229](https://github.com/
|
100
|
+
* Upgraded dry-validation dependency to dry-schema 1.0 ([#224](https://github.com/rubyconfig/config/pull/224))
|
101
|
+
* Moved constant to be defined on `Object` instead of `Kernel` ([#227](https://github.com/rubyconfig/config/issues/227))
|
102
|
+
* Add TruffleRuby to the test matrix ([#229](https://github.com/rubyconfig/config/issues/229))
|
23
103
|
|
24
104
|
## 1.7.2
|
25
105
|
|
26
106
|
### Bug fixes
|
27
107
|
|
28
|
-
* Lock max version of dry-validation depending on the ruby version ([#223](https://github.com/
|
108
|
+
* Lock max version of dry-validation depending on the ruby version ([#223](https://github.com/rubyconfig/config/pull/223))
|
29
109
|
|
30
110
|
## 1.7.1
|
31
111
|
|
32
112
|
### New features
|
33
113
|
|
34
|
-
* Upgrade dependencies ([#211](https://github.com/
|
114
|
+
* Upgrade dependencies ([#211](https://github.com/rubyconfig/config/pull/211))
|
35
115
|
|
36
116
|
### Changes
|
37
117
|
|
38
|
-
* Add Ruby 2.5 and Rails 5.1 to the testing matrix on Travis ([#201](https://github.com/
|
39
|
-
* Add Ruby 2.6
|
40
|
-
* Add Rails 5.2 to the test matrix ([#212](https://github.com/
|
118
|
+
* Add Ruby 2.5 and Rails 5.1 to the testing matrix on Travis ([#201](https://github.com/rubyconfig/config/pull/201))
|
119
|
+
* Add Ruby 2.6 to the test matrix ([#210](https://github.com/rubyconfig/config/pull/210))
|
120
|
+
* Add Rails 5.2 to the test matrix ([#212](https://github.com/rubyconfig/config/pull/212))
|
41
121
|
|
42
122
|
## 1.7.0
|
43
123
|
|
44
124
|
### New features
|
45
125
|
|
46
|
-
* **WARNING:** `nil` values will from now on overwrite an existing value when merging configs! This change of behavior can be reverted via `config.merge_nil_values = false` in your Config initializer ([#196](https://github.com/
|
126
|
+
* **WARNING:** `nil` values will from now on overwrite an existing value when merging configs! This change of behavior can be reverted via `config.merge_nil_values = false` in your Config initializer ([#196](https://github.com/rubyconfig/config/pull/196))
|
47
127
|
|
48
128
|
## 1.6.1
|
49
129
|
|
50
130
|
### Bug fixes
|
51
131
|
|
52
|
-
* Make dry-validation dependency less strict allowing to use newer versions ([#183](https://github.com/
|
53
|
-
* Fix `key?` and `has_key?`, which raise NoMethodError in non Rails environment, by using ActiveSupport `#delegate` implicitly ([#185](https://github.com/
|
54
|
-
* Update `deep_merge` dependency to latest version (v1.2.1) ([#191](https://github.com/
|
55
|
-
* Upgrade `rubocop` to version 0.52.1 ([#193](https://github.com/
|
56
|
-
* Add `zip` to the list of reserved keywords ([#197](https://github.com/
|
132
|
+
* Make dry-validation dependency less strict allowing to use newer versions ([#183](https://github.com/rubyconfig/config/pull/183))
|
133
|
+
* Fix `key?` and `has_key?`, which raise NoMethodError in non Rails environment, by using ActiveSupport `#delegate` implicitly ([#185](https://github.com/rubyconfig/config/pull/185))
|
134
|
+
* Update `deep_merge` dependency to latest version (v1.2.1) ([#191](https://github.com/rubyconfig/config/pull/191))
|
135
|
+
* Upgrade `rubocop` to version 0.52.1 ([#193](https://github.com/rubyconfig/config/pull/193))
|
136
|
+
* Add `zip` to the list of reserved keywords ([#197](https://github.com/rubyconfig/config/pull/197))
|
57
137
|
|
58
138
|
## 1.6.0
|
59
139
|
|
60
140
|
### New features
|
61
141
|
|
62
142
|
* `Config#fail_on_missing` option (default `false`) to raise a `KeyError` exception when accessing a non-existing key
|
63
|
-
* Add ability to test if a value was set for a given key with `key?` and `has_key?` ([#182](https://github.com/
|
143
|
+
* Add ability to test if a value was set for a given key with `key?` and `has_key?` ([#182](https://github.com/rubyconfig/config/pull/182))
|
64
144
|
|
65
145
|
## 1.5.1
|
66
146
|
|
67
147
|
### New features
|
68
148
|
|
69
|
-
* Add parsing of ENV variable values to Boolean type ([#180](https://github.com/
|
149
|
+
* Add parsing of ENV variable values to Boolean type ([#180](https://github.com/rubyconfig/config/pull/180))
|
70
150
|
|
71
151
|
## 1.5.0
|
72
152
|
|
73
153
|
### New features
|
74
154
|
|
75
|
-
* Add ability to validate config schema ([#155](https://github.com/
|
76
|
-
* Add count to the reserved names list ([#167](https://github.com/
|
155
|
+
* Add ability to validate config schema ([#155](https://github.com/rubyconfig/config/pull/155) thanks to [@ok32](https://github.com/ok32))
|
156
|
+
* Add count to the reserved names list ([#167](https://github.com/rubyconfig/config/pull/167) thanks to [@carbonin](https://github.com/carbonin))
|
77
157
|
|
78
158
|
### Bug fixes
|
79
159
|
|
80
|
-
* Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/
|
160
|
+
* Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/rubyconfig/config/pull/177) thanks to [@rdodson41](https://github.com/rdodson41))
|
81
161
|
|
82
162
|
## 1.4.0
|
83
163
|
|
84
164
|
### New features
|
85
165
|
|
86
|
-
* Added support for passing a raw ruby hash into to both `Settings.add_source!` and `Settings.prepend_source!` ([#108](https://github.com/
|
166
|
+
* Added support for passing a raw ruby hash into to both `Settings.add_source!` and `Settings.prepend_source!` ([#108](https://github.com/rubyconfig/config/pull/159) thanks to [@halloffame](https://github.com/halloffame))
|
87
167
|
|
88
168
|
### Bug fixes
|
89
169
|
|
90
|
-
* Added new reserved name `test` ([#158](https://github.com/
|
91
|
-
* `to_hash` should not replace nested config objects with Hash ([#160](https://github.com/
|
170
|
+
* Added new reserved name `test` ([#158](https://github.com/rubyconfig/config/pull/158) thanks to [@milushov](https://github.com/milushov))
|
171
|
+
* `to_hash` should not replace nested config objects with Hash ([#160](https://github.com/rubyconfig/config/issues/160) thanks to [@seikichi](https://github.com/seikichi))
|
92
172
|
|
93
173
|
## 1.3.0
|
94
174
|
|
95
|
-
* **WARNING:** Overwrite arrays found in previously loaded settings file ([#137](https://github.com/
|
175
|
+
* **WARNING:** Overwrite arrays found in previously loaded settings file ([#137](https://github.com/rubyconfig/config/pull/137) thanks to [@Fryguy](https://github.com/Fryguy) and [@dtaniwaki](https://github.com/dtaniwaki)) - this is a change breaking previous behaviour. If you want to keep Config to work as before, which is merging arrays found in following loaded settings file, please add `config.overwrite_arrays = false` to your Config initializer
|
96
176
|
* Changed default ENV variables loading settings to downcase variable names and parse values
|
97
177
|
* Added parsing ENV variables values to Float type
|
98
|
-
* Change method definition order in Rails integration module to prevent undefined method `preload` error (based on [@YaroSpace](https://github.com/YaroSpace) suggestion in [#111](https://github.com/
|
178
|
+
* Change method definition order in Rails integration module to prevent undefined method `preload` error (based on [@YaroSpace](https://github.com/YaroSpace) suggestion in [#111](https://github.com/rubyconfig/config/issues/111)
|
99
179
|
|
100
180
|
## 1.2.1
|
101
181
|
|
102
|
-
* Fixed support for multilevel settings loaded from ENV variables (inspired by [@cbeer](https://github.com/cbeer) in [#144](https://github.com/
|
182
|
+
* Fixed support for multilevel settings loaded from ENV variables (inspired by [@cbeer](https://github.com/cbeer) in [#144](https://github.com/rubyconfig/config/pull/144))
|
103
183
|
|
104
184
|
## 1.2.0
|
105
185
|
|
106
|
-
* Add ability to load settings from ENV variables ([#108](https://github.com/
|
107
|
-
* Removed Rails 5 deprecation warnings for prepend_before_filter ([#141](https://github.com/
|
186
|
+
* Add ability to load settings from ENV variables ([#108](https://github.com/rubyconfig/config/issues/108) thanks to [@vinceve](https://github.com/vinceve) and [@spalladino](https://github.com/spalladino))
|
187
|
+
* Removed Rails 5 deprecation warnings for prepend_before_filter ([#141](https://github.com/rubyconfig/config/pull/141))
|
108
188
|
|
109
189
|
## 1.1.1
|
110
190
|
|
111
|
-
* Downgrade minimum ruby version to 2.0.0 ([#136](https://github.com/
|
191
|
+
* Downgrade minimum ruby version to 2.0.0 ([#136](https://github.com/rubyconfig/config/issues/136))
|
112
192
|
|
113
193
|
## 1.1.0
|
114
194
|
|
@@ -117,12 +197,12 @@ If you need older version of Ruby or Rails, please stick to 1.x version of this
|
|
117
197
|
|
118
198
|
## 1.0.0
|
119
199
|
|
120
|
-
* `
|
121
|
-
* Fixed array descent when converting to hash ([#89](https://github.com/
|
122
|
-
* Catch OpenStruct reserved keywords ([#95](https://github.com/
|
123
|
-
* Allows loading before app configuration process ([#107](https://github.com/
|
124
|
-
* `deep_merge` is now properly managed via gemspec ([#110](https://github.com/
|
125
|
-
* Added `prepend_source!` ([#102](https://github.com/
|
200
|
+
* `rubyconfig` is now officially renamed to `Config`
|
201
|
+
* Fixed array descent when converting to hash ([#89](https://github.com/rubyconfig/config/pull/89))
|
202
|
+
* Catch OpenStruct reserved keywords ([#95](https://github.com/rubyconfig/config/pull/95) by [@dudo](https://github.com/dudo))
|
203
|
+
* Allows loading before app configuration process ([#107](https://github.com/rubyconfig/config/pull/107) by [@Antiarchitect](https://github.com/Antiarchitect))
|
204
|
+
* `deep_merge` is now properly managed via gemspec ([#110](https://github.com/rubyconfig/config/pull/110))
|
205
|
+
* Added `prepend_source!` ([#102](https://github.com/rubyconfig/config/pull/102))
|
126
206
|
|
127
207
|
## 0.99
|
128
208
|
|
data/CONTRIBUTING.md
ADDED
@@ -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 *.md
|
32
|
+
```
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# Config
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/config)
|
4
|
+
[](https://rubygems.org/gems/config)
|
5
|
+
[](https://rubygems.org/gems/config)
|
6
|
+
[](https://github.com/rubyconfig/config/actions?query=branch%3Amaster)
|
7
|
+
[](https://opencollective.com/rubyconfig)
|
7
8
|
|
8
9
|
## Summary
|
9
10
|
|
@@ -20,11 +21,14 @@ Config helps you easily manage environment specific settings in an easy and usab
|
|
20
21
|
|
21
22
|
## Compatibility
|
22
23
|
|
24
|
+
Current version supports and is [tested](.github/workflows/tests.yml#L19) for the following interpreters and frameworks:
|
25
|
+
|
23
26
|
* Interpreters
|
24
|
-
* [Ruby](https://www.ruby-lang.org
|
25
|
-
* [
|
27
|
+
* [Ruby](https://www.ruby-lang.org) `>= 2.4`
|
28
|
+
* [JRuby](https://www.jruby.org) `>= 9.2`
|
29
|
+
* [TruffleRuby](https://github.com/oracle/truffleruby) `>= 19.3`
|
26
30
|
* Application frameworks
|
27
|
-
* Rails `>= 4.2` and `
|
31
|
+
* Rails `>= 4.2`, `5` and `6`
|
28
32
|
* Padrino
|
29
33
|
* Sinatra
|
30
34
|
|
@@ -41,6 +45,7 @@ Add `gem 'config'` to your `Gemfile` and run `bundle install` to install it. The
|
|
41
45
|
which will generate customizable config file `config/initializers/config.rb` and set of default settings files:
|
42
46
|
|
43
47
|
config/settings.yml
|
48
|
+
config/settings.local.yml
|
44
49
|
config/settings/development.yml
|
45
50
|
config/settings/production.yml
|
46
51
|
config/settings/test.yml
|
@@ -57,8 +62,7 @@ register Config
|
|
57
62
|
|
58
63
|
### Installing on Sinatra
|
59
64
|
|
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.
|
65
|
+
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
66
|
|
63
67
|
```ruby
|
64
68
|
set :root, File.dirname(__FILE__)
|
@@ -67,15 +71,13 @@ register Config
|
|
67
71
|
|
68
72
|
### Installing on other ruby projects
|
69
73
|
|
70
|
-
Add the gem to your `Gemfile` and run `bundle install` to install it.
|
71
|
-
Then initialize `Config` manually within your configure block.
|
74
|
+
Add the gem to your `Gemfile` and run `bundle install` to install it. Then initialize `Config` manually within your configure block.
|
72
75
|
|
73
76
|
```ruby
|
74
77
|
Config.load_and_set_settings(Config.setting_files("/path/to/config_root", "your_project_environment"))
|
75
78
|
```
|
76
79
|
|
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.
|
80
|
+
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
81
|
|
80
82
|
```ruby
|
81
83
|
Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
|
@@ -83,8 +85,7 @@ Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
|
|
83
85
|
|
84
86
|
## Accessing the Settings object
|
85
87
|
|
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.
|
88
|
+
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
89
|
|
89
90
|
config/settings.yml
|
90
91
|
config/settings/#{environment}.yml
|
@@ -136,8 +137,7 @@ Settings.reload_from_files(
|
|
136
137
|
|
137
138
|
### Environment specific config files
|
138
139
|
|
139
|
-
You can have environment specific config files. Environment specific config entries take precedence over common config
|
140
|
-
entries.
|
140
|
+
You can have environment specific config files. Environment specific config entries take precedence over common config entries.
|
141
141
|
|
142
142
|
Example development environment config file:
|
143
143
|
|
@@ -153,8 +153,7 @@ Example production environment config file:
|
|
153
153
|
|
154
154
|
### Developer specific config files
|
155
155
|
|
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` :
|
156
|
+
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
157
|
|
159
158
|
```ruby
|
160
159
|
Rails.root.join("config", "settings.local.yml").to_s,
|
@@ -162,6 +161,8 @@ Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
|
|
162
161
|
Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
|
163
162
|
```
|
164
163
|
|
164
|
+
**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.
|
165
|
+
|
165
166
|
### Adding sources at runtime
|
166
167
|
|
167
168
|
You can add new YAML config files at runtime. Just use:
|
@@ -180,19 +181,18 @@ Settings.prepend_source!("/path/to/source.yml")
|
|
180
181
|
Settings.reload!
|
181
182
|
```
|
182
183
|
|
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.
|
184
|
+
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
185
|
|
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
|
186
|
+
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
187
|
|
189
188
|
```ruby
|
190
189
|
Settings.add_source!("#{Rails.root}/config/settings/local.yml")
|
191
190
|
Settings.reload!
|
192
191
|
```
|
193
192
|
|
194
|
-
> Note: this is an example usage, it is easier to just use the default local
|
195
|
-
settings
|
193
|
+
> Note: this is an example usage, it is easier to just use the default local
|
194
|
+
> files `settings.local.yml`, `settings/#{Rails.env}.local.yml` and
|
195
|
+
> `environments/#{Rails.env}.local.yml` for your developer specific settings.
|
196
196
|
|
197
197
|
You also have the option to add a raw hash as a source. One use case might be storing settings in the database or in environment variables that overwrite what is in the YML files.
|
198
198
|
|
@@ -252,18 +252,16 @@ Settings.section.servers[1].name # => amazon.com
|
|
252
252
|
|
253
253
|
## Configuration
|
254
254
|
|
255
|
-
There are multiple configuration options available, however you can customize `Config` only once, preferably during
|
256
|
-
application initialization phase:
|
255
|
+
There are multiple configuration options available, however you can customize `Config` only once, preferably during application initialization phase:
|
257
256
|
|
258
257
|
```ruby
|
259
258
|
Config.setup do |config|
|
260
259
|
config.const_name = 'Settings'
|
261
|
-
...
|
260
|
+
# ...
|
262
261
|
end
|
263
262
|
```
|
264
263
|
|
265
|
-
After installing `Config` in Rails, you will find automatically generated file that contains default configuration
|
266
|
-
located at `config/initializers/config.rb`.
|
264
|
+
After installing `Config` in Rails, you will find automatically generated file that contains default configuration located at `config/initializers/config.rb`.
|
267
265
|
|
268
266
|
### General
|
269
267
|
|
@@ -300,12 +298,52 @@ Check [Deep Merge](https://github.com/danielsdeleo/deep_merge) for more details.
|
|
300
298
|
|
301
299
|
### Validation
|
302
300
|
|
303
|
-
With Ruby 2.1 or newer, you can optionally define a schema to validate presence (and type) of specific config values
|
301
|
+
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.
|
302
|
+
|
303
|
+
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.
|
304
|
+
|
305
|
+
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.
|
306
|
+
|
307
|
+
#### Contract
|
308
|
+
|
309
|
+
Leverage dry-validation, you can create a contract with a params schema and rules:
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
class ConfigContract < Dry::Validation::Contract
|
313
|
+
params do
|
314
|
+
optional(:email).maybe(:str?)
|
315
|
+
|
316
|
+
required(:youtube).schema do
|
317
|
+
required(:api_key).filled
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
rule(:email) do
|
322
|
+
unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
|
323
|
+
key.failure('has invalid format')
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
Config.setup do |config|
|
329
|
+
config.validation_contract = ConfigContract.new
|
330
|
+
end
|
331
|
+
```
|
332
|
+
|
333
|
+
The above example adds a rule to ensure the `email` is valid by matching it against the provided regular expression.
|
334
|
+
|
335
|
+
Check [dry-validation](https://github.com/dry-rb/dry-validation) for more details.
|
336
|
+
|
337
|
+
#### Schema
|
338
|
+
|
339
|
+
You may also specify a schema using [dry-schema](https://github.com/dry-rb/dry-schema):
|
304
340
|
|
305
341
|
```ruby
|
306
342
|
Config.setup do |config|
|
307
343
|
# ...
|
308
344
|
config.schema do
|
345
|
+
optional(:email).maybe(:str?)
|
346
|
+
|
309
347
|
required(:youtube).schema do
|
310
348
|
required(:api_key).filled
|
311
349
|
end
|
@@ -313,13 +351,6 @@ Config.setup do |config|
|
|
313
351
|
end
|
314
352
|
```
|
315
353
|
|
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
354
|
Check [dry-schema](https://github.com/dry-rb/dry-schema) for more details.
|
324
355
|
|
325
356
|
### Missing keys
|
@@ -371,8 +402,7 @@ See section below for more details.
|
|
371
402
|
|
372
403
|
## Working with environment variables
|
373
404
|
|
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:
|
405
|
+
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
406
|
|
377
407
|
```ruby
|
378
408
|
Config.setup do |config|
|
@@ -381,8 +411,7 @@ Config.setup do |config|
|
|
381
411
|
end
|
382
412
|
```
|
383
413
|
|
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`:
|
414
|
+
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
415
|
|
387
416
|
```ruby
|
388
417
|
ENV['Settings.section.size'] = 1
|
@@ -391,11 +420,24 @@ ENV['Settings.section.server'] = 'google.com'
|
|
391
420
|
|
392
421
|
It won't work with arrays, though.
|
393
422
|
|
423
|
+
It is considered an error to use environment variables to simutaneously assign a "flat" value and a multi-level value to a key.
|
424
|
+
|
425
|
+
```ruby
|
426
|
+
# Raises an error when settings are loaded
|
427
|
+
ENV['BACKEND_DATABASE'] = 'development'
|
428
|
+
ENV['BACKEND_DATABASE_USER'] = 'postgres'
|
429
|
+
```
|
430
|
+
|
431
|
+
Instead, specify keys of equal depth in the environment variable names:
|
432
|
+
|
433
|
+
```ruby
|
434
|
+
ENV['BACKEND_DATABASE_NAME'] = 'development'
|
435
|
+
ENV['BACKEND_DATABASE_USER'] = 'postgres'
|
436
|
+
```
|
437
|
+
|
394
438
|
### Working with Heroku
|
395
439
|
|
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.
|
440
|
+
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
441
|
|
400
442
|
To upload your local values to Heroku you could ran `bundle exec rake config:heroku`.
|
401
443
|
|
@@ -403,10 +445,8 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her
|
|
403
445
|
|
404
446
|
You can customize how environment variables are processed:
|
405
447
|
|
406
|
-
* `env_prefix` (default: `
|
407
|
-
* `env_separator` (default:
|
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)
|
448
|
+
* `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive)
|
449
|
+
* `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
450
|
* `env_converter` (default: `:downcase`) - how to process variables names:
|
411
451
|
* `nil` - no change
|
412
452
|
* `:downcase` - convert to lower case
|
@@ -440,33 +480,56 @@ Settings.section.server # => 'google.com'
|
|
440
480
|
Settings.section.ssl_enabled # => false
|
441
481
|
```
|
442
482
|
|
443
|
-
|
483
|
+
### Working with AWS Secrets Manager
|
444
484
|
|
445
|
-
|
485
|
+
It is possible to parse variables stored in an AWS Secrets Manager Secret as if they were environment variables by using `Config::Sources::EnvSource`.
|
446
486
|
|
447
|
-
|
448
|
-
|
449
|
-
|
487
|
+
For example, the plaintext secret might look like this:
|
488
|
+
|
489
|
+
```json
|
490
|
+
{
|
491
|
+
"Settings.foo": "hello",
|
492
|
+
"Settings.bar": "world",
|
493
|
+
}
|
450
494
|
```
|
451
495
|
|
452
|
-
|
496
|
+
In order to load those settings, fetch the settings from AWS Secrets Manager, parse the plaintext as JSON, pass the resulting `Hash` into a new `EnvSource`, load the new source, and reload.
|
453
497
|
|
454
|
-
```
|
455
|
-
|
498
|
+
```ruby
|
499
|
+
# fetch secrets from AWS
|
500
|
+
client = Aws::SecretsManager::Client.new
|
501
|
+
response = client.get_secret_value(secret_id: "#{ENV['ENVIRONMENT']}/my_application")
|
502
|
+
secrets = JSON.parse(response.secret_string)
|
503
|
+
|
504
|
+
# load secrets into config
|
505
|
+
secret_source = Config::Sources::EnvSource.new(secrets)
|
506
|
+
Settings.add_source!(secret_source)
|
507
|
+
Settings.reload!
|
456
508
|
```
|
457
509
|
|
458
|
-
|
510
|
+
In this case, the following settings will be available:
|
459
511
|
|
460
|
-
```
|
461
|
-
|
512
|
+
```ruby
|
513
|
+
Settings.foo # => "hello"
|
514
|
+
Settings.bar # => "world"
|
462
515
|
```
|
463
516
|
|
464
|
-
|
517
|
+
By default, `EnvSource` will use configuration for `env_prefix`, `env_separator`, `env_converter`, and `env_parse_values`, but any of these can be overridden in the constructor.
|
465
518
|
|
466
|
-
```
|
467
|
-
|
519
|
+
```ruby
|
520
|
+
secret_source = Config::Sources::EnvSource.new(secrets,
|
521
|
+
prefix: 'MyConfig',
|
522
|
+
separator: '__',
|
523
|
+
converter: nil,
|
524
|
+
parse_values: false)
|
468
525
|
```
|
469
526
|
|
527
|
+
## Contributing
|
528
|
+
|
529
|
+
You are very warmly welcome to help. Please follow our [contribution guidelines](CONTRIBUTING.md)
|
530
|
+
|
531
|
+
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.
|
532
|
+
|
470
533
|
## Authors
|
471
534
|
|
472
535
|
* [Piotr Kuczynski](http://github.com/pkuczynski)
|
@@ -474,6 +537,28 @@ mdl --style .mdlstyle.rb *.md
|
|
474
537
|
* [Jacques Crocker](http://github.com/railsjedi)
|
475
538
|
* Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
|
476
539
|
|
540
|
+
## Contributors
|
541
|
+
|
542
|
+
### Code Contributors
|
543
|
+
|
544
|
+
This project exists thanks to all the people who contribute and you are very warmly welcome to help. Please follow our [contribution guidelines](CONTRIBUTING.md).
|
545
|
+
|
546
|
+
Any and all contributions offered in any form, past present or future are understood to be in complete agreement and acceptance with the [MIT](LICENSE) license.
|
547
|
+
|
548
|
+
[](https://github.com/rubyconfig/config/graphs/contributors)
|
549
|
+
|
550
|
+
### Financial Contributors
|
551
|
+
|
552
|
+
[Become a backer](https://opencollective.com/rubyconfig#backer) and support us with a small monthly donation to help us continue our activities. Thank you if you already one! 🙏
|
553
|
+
|
554
|
+
[](https://opencollective.com/rubyconfig)
|
555
|
+
|
556
|
+
#### Sponsors
|
557
|
+
|
558
|
+
Support this project by becoming a [sponsor](https://opencollective.com/rubyconfig#sponsor). Your logo will show up here with a link to your website.
|
559
|
+
|
560
|
+
[](https://opencollective.com/rubyconfig)
|
561
|
+
|
477
562
|
## License
|
478
563
|
|
479
|
-
|
564
|
+
Copyright (C) Piotr Kuczynski. Released under the [MIT License](LICENSE.md).
|