config 1.7.0 → 3.0.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: b706fa8c599dff6bd37f9faf7ef9846cdfa712f0b4bd97b2164e9b481277647b
4
- data.tar.gz: 9b4345f38ef41b3c1ad466eabeb57ec506eb8f1386bef5ec50d094f4fe74006a
3
+ metadata.gz: a9553d786b6f2a87d956e85494f9f8fd083e42076989e7c8217b84f72b1d6469
4
+ data.tar.gz: 592b1002dd18e793f444c2b4d00220c4cbbaf2f1e850d33c0d6c5bc5c41ae236
5
5
  SHA512:
6
- metadata.gz: 0a049ea2053deecc4929019a6e1bc059f2907f222515b1e7f51063b5ab59f42e3fefa4238ba04c97cd2cafc7aeb4e26a4d7e9b25cad5f63d6cdabd33316ec011
7
- data.tar.gz: 70288ae9514f87bd3ed855292a4cf6a525eff7a23ae7bb585c7b785c585683cceec79f5751516739758b05ecf5673ec615461d8a13b5cddff97ef326309616fc
6
+ metadata.gz: 80c5e1c7de910d8f7592b0bf2d1ad322dbf8aa6565617ca1f5d0bdede78316073aa5afb5bf6e7cb33ce42bace7770f4cb8f8a86d4fd13a31fc0e900e58c6ae9c
7
+ data.tar.gz: 8fe4ecdb8069e910c36f68cb3a55863182797539638be36f7be622057174a45f4605427aaa0f145fd399a518131310059408812e9ff5dd391a1c7691b45624a7
data/CHANGELOG.md CHANGED
@@ -4,75 +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
+
87
+ ## 2.0.0
88
+
89
+ ### BREAKING CHANGES
90
+
91
+ After upgrade to dry-schema 1.0 we had to drop support for Rails `< 4.2` and Ruby `< 2.4`.
92
+ If you need older version of Ruby or Rails, please stick to 1.x version of this gem.
93
+
94
+ ### New features
95
+
96
+ * Add `merge_hash_arrays` as a configuration option ([#214](https://github.com/rubyconfig/config/pull/214))
97
+
98
+ ### Changes
99
+
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))
103
+
104
+ ## 1.7.2
105
+
106
+ ### Bug fixes
107
+
108
+ * Lock max version of dry-validation depending on the ruby version ([#223](https://github.com/rubyconfig/config/pull/223))
109
+
110
+ ## 1.7.1
111
+
112
+ ### New features
113
+
114
+ * Upgrade dependencies ([#211](https://github.com/rubyconfig/config/pull/211))
115
+
116
+ ### Changes
117
+
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))
121
+
7
122
  ## 1.7.0
8
123
 
9
- **New features:**
124
+ ### New features
10
125
 
11
- * **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/railsconfig/config/pull/196))
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))
12
127
 
13
128
  ## 1.6.1
14
129
 
15
- **Bug fixes:**
16
- * Make dry-validation dependency less strict allowing to use newer versions ([#183](https://github.com/railsconfig/config/pull/183))
17
- * Fix `key?` and `has_key?`, which raise NoMethodError in non Rails environment, by using ActiveSupport `#delegate` implicitly ([#185](https://github.com/railsconfig/config/pull/185))
18
- * Update `deep_merge` dependency to latest version (v1.2.1) ([#191](https://github.com/railsconfig/config/pull/191))
19
- * Upgrade `rubocop` to version 0.52.1 ([#193](https://github.com/railsconfig/config/pull/193))
20
- * Add `zip` to the list of reserved keywords ([#197](https://github.com/railsconfig/config/pull/197))
130
+ ### Bug fixes
131
+
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))
21
137
 
22
138
  ## 1.6.0
23
139
 
24
- **New features:**
140
+ ### New features
25
141
 
26
142
  * `Config#fail_on_missing` option (default `false`) to raise a `KeyError` exception when accessing a non-existing key
27
- * Add ability to test if a value was set for a given key with `key?` and `has_key?` ([#182](https://github.com/railsconfig/config/pull/182))
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))
28
144
 
29
145
  ## 1.5.1
30
146
 
31
- **New features:**
147
+ ### New features
32
148
 
33
- * Add parsing of ENV variable values to Boolean type ([#180](https://github.com/railsconfig/config/pull/180))
149
+ * Add parsing of ENV variable values to Boolean type ([#180](https://github.com/rubyconfig/config/pull/180))
34
150
 
35
151
  ## 1.5.0
36
152
 
37
- **New features:**
153
+ ### New features
38
154
 
39
- * Add ability to validate config schema ([#155](https://github.com/railsconfig/config/pull/155) thanks to [@ok32](https://github.com/ok32))
40
- * Add count to the reserved names list ([#167](https://github.com/railsconfig/config/pull/167) thanks to [@carbonin](https://github.com/carbonin))
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))
41
157
 
42
- **Bug fixes:**
158
+ ### Bug fixes
43
159
 
44
- * Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/railsconfig/config/pull/177) thanks to [@rdodson41](https://github.com/rdodson41))
160
+ * Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/rubyconfig/config/pull/177) thanks to [@rdodson41](https://github.com/rdodson41))
45
161
 
46
162
  ## 1.4.0
47
163
 
48
- **New features:**
164
+ ### New features
49
165
 
50
- * Added support for passing a raw ruby hash into to both `Settings.add_source!` and `Settings.prepend_source!` ([#108](https://github.com/railsconfig/config/pull/159) thanks to [@halloffame](https://github.com/halloffame))
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))
51
167
 
52
- **Bug fixes:**
168
+ ### Bug fixes
53
169
 
54
- * Added new reserved name `test` ([#158](https://github.com/railsconfig/config/pull/158) thanks to [@milushov](https://github.com/milushov))
55
- * `to_hash` should not replace nested config objects with Hash ([#160](https://github.com/railsconfig/config/issues/160) thanks to [@seikichi](https://github.com/seikichi))
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))
56
172
 
57
173
  ## 1.3.0
58
174
 
59
- * **WARNING:** Overwrite arrays found in previously loaded settings file ([#137](https://github.com/railsconfig/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
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
60
176
  * Changed default ENV variables loading settings to downcase variable names and parse values
61
177
  * Added parsing ENV variables values to Float type
62
- * 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/railsconfig/config/issues/111)
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)
63
179
 
64
180
  ## 1.2.1
65
181
 
66
- * Fixed support for multilevel settings loaded from ENV variables (inspired by [@cbeer](https://github.com/cbeer) in [#144](https://github.com/railsconfig/config/pull/144))
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))
67
183
 
68
184
  ## 1.2.0
69
185
 
70
- * Add ability to load settings from ENV variables ([#108](https://github.com/railsconfig/config/issues/108) thanks to [@vinceve](https://github.com/vinceve) and [@spalladino](https://github.com/spalladino))
71
- * Removed Rails 5 deprecation warnings for prepend_before_filter ([#141](https://github.com/railsconfig/config/pull/141))
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))
72
188
 
73
189
  ## 1.1.1
74
190
 
75
- * Downgrade minimum ruby version to 2.0.0 ([#136](https://github.com/railsconfig/config/issues/136))
191
+ * Downgrade minimum ruby version to 2.0.0 ([#136](https://github.com/rubyconfig/config/issues/136))
76
192
 
77
193
  ## 1.1.0
78
194
 
@@ -81,12 +197,12 @@
81
197
 
82
198
  ## 1.0.0
83
199
 
84
- * `RailsConfig` is now officially renamed to `Config`
85
- * Fixed array descent when converting to hash ([#89](https://github.com/railsconfig/config/pull/89))
86
- * Catch OpenStruct reserved keywords ([#95](https://github.com/railsconfig/config/pull/95) by [@dudo](https://github.com/dudo))
87
- * Allows loading before app configuration process ([#107](https://github.com/railsconfig/config/pull/107) by [@Antiarchitect](https://github.com/Antiarchitect))
88
- * `deep_merge` is now properly managed via gemspec ([#110](https://github.com/railsconfig/config/pull/110))
89
- * Added `prepend_source!` ([#102](https://github.com/railsconfig/config/pull/102))
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))
90
206
 
91
207
  ## 0.99
92
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,10 +1,10 @@
1
1
  # Config
2
2
 
3
- [![Build Status](https://api.travis-ci.org/railsconfig/config.svg?branch=master)](http://travis-ci.org/railsconfig/config)
4
- [![Gem Version](https://badge.fury.io/rb/config.svg)](http://badge.fury.io/rb/config)
5
- [![Dependency Status](https://gemnasium.com/railsconfig/config.svg)](https://gemnasium.com/railsconfig/config)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/maintainability)](https://codeclimate.com/github/railsconfig/config/maintainability)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/test_coverage)](https://codeclimate.com/github/railsconfig/config/test_coverage)
3
+ [![Version](https://img.shields.io/gem/v/config)](https://rubygems.org/gems/config)
4
+ [![Downloads Total](https://img.shields.io/gem/dt/config)](https://rubygems.org/gems/config)
5
+ [![Build](https://img.shields.io/github/workflow/status/rubyconfig/config/tests)](https://rubygems.org/gems/config)
6
+ [![Tests](https://github.com/rubyconfig/config/workflows/tests/badge.svg)](https://github.com/rubyconfig/config/actions?query=branch%3Amaster)
7
+ [![Financial Contributors on Open Collective](https://opencollective.com/rubyconfig/all/badge.svg?label=backers)](https://opencollective.com/rubyconfig)
8
8
 
9
9
  ## Summary
10
10
 
@@ -21,16 +21,22 @@ Config helps you easily manage environment specific settings in an easy and usab
21
21
 
22
22
  ## Compatibility
23
23
 
24
- * Ruby `2.x`
25
- * Rails `>= 3.1`, `4` and `5`
26
- * Padrino
27
- * Sinatra
24
+ Current version supports and is [tested](.github/workflows/tests.yml#L19) for the following interpreters and frameworks:
28
25
 
29
- For older versions of Rails or Ruby use [AppConfig](http://github.com/fredwu/app_config).
26
+ * Interpreters
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`
30
+ * Application frameworks
31
+ * Rails `>= 4.2`, `5` and `6`
32
+ * Padrino
33
+ * Sinatra
34
+
35
+ For Ruby `2.0` to `2.3` or Rails `3` to `4.1` use version `1.x` of this gem. For older versions of Rails or Ruby use [AppConfig](http://github.com/fredwu/app_config).
30
36
 
31
37
  ## Installing
32
38
 
33
- ### Installing on Rails 3, 4 or 5
39
+ ### Installing on Rails
34
40
 
35
41
  Add `gem 'config'` to your `Gemfile` and run `bundle install` to install it. Then run
36
42
 
@@ -39,6 +45,7 @@ Add `gem 'config'` to your `Gemfile` and run `bundle install` to install it. The
39
45
  which will generate customizable config file `config/initializers/config.rb` and set of default settings files:
40
46
 
41
47
  config/settings.yml
48
+ config/settings.local.yml
42
49
  config/settings/development.yml
43
50
  config/settings/production.yml
44
51
  config/settings/test.yml
@@ -55,8 +62,7 @@ register Config
55
62
 
56
63
  ### Installing on Sinatra
57
64
 
58
- Add the gem to your `Gemfile` and run `bundle install` to install it. Afterwards in need to register `Config` in your
59
- 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.
60
66
 
61
67
  ```ruby
62
68
  set :root, File.dirname(__FILE__)
@@ -65,15 +71,13 @@ register Config
65
71
 
66
72
  ### Installing on other ruby projects
67
73
 
68
- Add the gem to your `Gemfile` and run `bundle install` to install it.
69
- 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.
70
75
 
71
76
  ```ruby
72
77
  Config.load_and_set_settings(Config.setting_files("/path/to/config_root", "your_project_environment"))
73
78
  ```
74
79
 
75
- It's also possible to initialize `Config` manually within your configure block if you want to just give it some yml
76
- 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.
77
81
 
78
82
  ```ruby
79
83
  Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
@@ -81,8 +85,7 @@ Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
81
85
 
82
86
  ## Accessing the Settings object
83
87
 
84
- After installing the gem, `Settings` object will become available globally and by default will be compiled from the
85
- 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.
86
89
 
87
90
  config/settings.yml
88
91
  config/settings/#{environment}.yml
@@ -134,8 +137,7 @@ Settings.reload_from_files(
134
137
 
135
138
  ### Environment specific config files
136
139
 
137
- You can have environment specific config files. Environment specific config entries take precedence over common config
138
- entries.
140
+ You can have environment specific config files. Environment specific config entries take precedence over common config entries.
139
141
 
140
142
  Example development environment config file:
141
143
 
@@ -151,8 +153,7 @@ Example production environment config file:
151
153
 
152
154
  ### Developer specific config files
153
155
 
154
- If you want to have local settings, specific to your machine or development environment,
155
- 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` :
156
157
 
157
158
  ```ruby
158
159
  Rails.root.join("config", "settings.local.yml").to_s,
@@ -160,6 +161,8 @@ Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
160
161
  Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
161
162
  ```
162
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
+
163
166
  ### Adding sources at runtime
164
167
 
165
168
  You can add new YAML config files at runtime. Just use:
@@ -178,19 +181,18 @@ Settings.prepend_source!("/path/to/source.yml")
178
181
  Settings.reload!
179
182
  ```
180
183
 
181
- This will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings
182
- 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.
183
185
 
184
- One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent
185
- 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
186
187
 
187
188
  ```ruby
188
189
  Settings.add_source!("#{Rails.root}/config/settings/local.yml")
189
190
  Settings.reload!
190
191
  ```
191
192
 
192
- > Note: this is an example usage, it is easier to just use the default local files `settings.local.yml,
193
- settings/#{Rails.env}.local.yml and environments/#{Rails.env}.local.yml` for your developer specific 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.
194
196
 
195
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.
196
198
 
@@ -250,18 +252,16 @@ Settings.section.servers[1].name # => amazon.com
250
252
 
251
253
  ## Configuration
252
254
 
253
- There are multiple configuration options available, however you can customize `Config` only once, preferably during
254
- application initialization phase:
255
+ There are multiple configuration options available, however you can customize `Config` only once, preferably during application initialization phase:
255
256
 
256
257
  ```ruby
257
258
  Config.setup do |config|
258
259
  config.const_name = 'Settings'
259
- ...
260
+ # ...
260
261
  end
261
262
  ```
262
263
 
263
- After installing `Config` in Rails, you will find automatically generated file that contains default configuration
264
- 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`.
265
265
 
266
266
  ### General
267
267
 
@@ -270,6 +270,7 @@ located at `config/initializers/config.rb`.
270
270
  ### Merge customization
271
271
 
272
272
  * `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true`
273
+ * `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false`
273
274
  * `knockout_prefix` - ability to remove elements of the array set in earlier loaded settings file. Makes sense only when `overwrite_arrays = false`, otherwise array settings would be overwritten by default. Default: `nil`
274
275
  * `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`.
275
276
 
@@ -297,12 +298,52 @@ Check [Deep Merge](https://github.com/danielsdeleo/deep_merge) for more details.
297
298
 
298
299
  ### Validation
299
300
 
300
- 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):
301
340
 
302
341
  ```ruby
303
342
  Config.setup do |config|
304
343
  # ...
305
344
  config.schema do
345
+ optional(:email).maybe(:str?)
346
+
306
347
  required(:youtube).schema do
307
348
  required(:api_key).filled
308
349
  end
@@ -310,14 +351,7 @@ Config.setup do |config|
310
351
  end
311
352
  ```
312
353
 
313
- The above example demonstrates how to ensure that the configuration has the `youtube` structure
314
- with the `api_key` field filled.
315
-
316
- If you define a schema it will automatically be used to validate your config. If validation fails it will
317
- raise a `Config::Validation::Error` containing a nice message with information about all the mismatches
318
- between the schema and your config.
319
-
320
- Check [dry-validation](https://github.com/dry-rb/dry-validation) for more details.
354
+ Check [dry-schema](https://github.com/dry-rb/dry-schema) for more details.
321
355
 
322
356
  ### Missing keys
323
357
 
@@ -368,8 +402,7 @@ See section below for more details.
368
402
 
369
403
  ## Working with environment variables
370
404
 
371
- To load environment variables from the `ENV` object, that will override any settings defined in files, set the `use_env`
372
- 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:
373
406
 
374
407
  ```ruby
375
408
  Config.setup do |config|
@@ -378,8 +411,7 @@ Config.setup do |config|
378
411
  end
379
412
  ```
380
413
 
381
- Now config would read values from the ENV object to the settings. For the example above it would look for keys starting
382
- 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`:
383
415
 
384
416
  ```ruby
385
417
  ENV['Settings.section.size'] = 1
@@ -388,11 +420,24 @@ ENV['Settings.section.server'] = 'google.com'
388
420
 
389
421
  It won't work with arrays, though.
390
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
+
391
438
  ### Working with Heroku
392
439
 
393
- Heroku uses ENV object to store sensitive settings. You cannot upload such files to Heroku because it's ephemeral
394
- filesystem gets recreated from the git sources on each instance refresh. To use config with Heroku just set the
395
- `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.
396
441
 
397
442
  To upload your local values to Heroku you could ran `bundle exec rake config:heroku`.
398
443
 
@@ -400,10 +445,8 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her
400
445
 
401
446
  You can customize how environment variables are processed:
402
447
 
403
- * `env_prefix` (default: `SETTINGS`) - which ENV variables to load into config
404
- * `env_separator` (default: `.`) - what string to use as level separator - default value of `.` works well with
405
- Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using
406
- 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)
407
450
  * `env_converter` (default: `:downcase`) - how to process variables names:
408
451
  * `nil` - no change
409
452
  * `:downcase` - convert to lower case
@@ -437,26 +480,56 @@ Settings.section.server # => 'google.com'
437
480
  Settings.section.ssl_enabled # => false
438
481
  ```
439
482
 
440
- ## Contributing
483
+ ### Working with AWS Secrets Manager
441
484
 
442
- Bootstrap
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`.
443
486
 
444
- ```bash
445
- appraisal install
487
+ For example, the plaintext secret might look like this:
488
+
489
+ ```json
490
+ {
491
+ "Settings.foo": "hello",
492
+ "Settings.bar": "world",
493
+ }
446
494
  ```
447
495
 
448
- Run the test suite:
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.
449
497
 
450
- ```bash
451
- appraisal rspec
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!
452
508
  ```
453
509
 
454
- If you modified any of the documentation files verify their format:
510
+ In this case, the following settings will be available:
455
511
 
456
- ```bash
457
- mdl --style .mdlstyle.rb *.md
512
+ ```ruby
513
+ Settings.foo # => "hello"
514
+ Settings.bar # => "world"
458
515
  ```
459
516
 
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.
518
+
519
+ ```ruby
520
+ secret_source = Config::Sources::EnvSource.new(secrets,
521
+ prefix: 'MyConfig',
522
+ separator: '__',
523
+ converter: nil,
524
+ parse_values: false)
525
+ ```
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
+
460
533
  ## Authors
461
534
 
462
535
  * [Piotr Kuczynski](http://github.com/pkuczynski)
@@ -464,6 +537,28 @@ mdl --style .mdlstyle.rb *.md
464
537
  * [Jacques Crocker](http://github.com/railsjedi)
465
538
  * Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
466
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
+ [![Contributors](https://opencollective.com/rubyconfig/contributors.svg?width=890&button=false)](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
+ [![Backers](https://opencollective.com/rubyconfig/backers.svg?width=890)](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
+ [![Sponsors](https://opencollective.com/rubyconfig/sponsors.svg?width=890)](https://opencollective.com/rubyconfig)
561
+
467
562
  ## License
468
563
 
469
- Config is released under the [MIT License](http://www.opensource.org/licenses/MIT).
564
+ Copyright (C) Piotr Kuczynski. Released under the [MIT License](LICENSE.md).