config 1.4.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
- SHA1:
3
- metadata.gz: 73118a0190819d693e81132bc4a2746a453dd74d
4
- data.tar.gz: 5c6a339dcfa60f444269f0ba45da298656297471
2
+ SHA256:
3
+ metadata.gz: a9553d786b6f2a87d956e85494f9f8fd083e42076989e7c8217b84f72b1d6469
4
+ data.tar.gz: 592b1002dd18e793f444c2b4d00220c4cbbaf2f1e850d33c0d6c5bc5c41ae236
5
5
  SHA512:
6
- metadata.gz: a28428c4f956dacbd9032fa97037819a15956eb0d694a48a4250425d3902ef9fd13bb67fcfdb011d1c67ea043476a386c2dd6e729de85a846ad13d2b772c67a5
7
- data.tar.gz: 35fa737c860ca76a6c6aac73ccbdab4e5e399cfdf214d357e26cdd9e00fa1e3652a4701bfb73adcca498981cf67bd10c35088fe510d925605f43087f7cccee0b
6
+ metadata.gz: 80c5e1c7de910d8f7592b0bf2d1ad322dbf8aa6565617ca1f5d0bdede78316073aa5afb5bf6e7cb33ce42bace7770f4cb8f8a86d4fd13a31fc0e900e58c6ae9c
7
+ data.tar.gz: 8fe4ecdb8069e910c36f68cb3a55863182797539638be36f7be622057174a45f4605427aaa0f145fd399a518131310059408812e9ff5dd391a1c7691b45624a7
data/CHANGELOG.md CHANGED
@@ -1,30 +1,194 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ...
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
+
122
+ ## 1.7.0
123
+
124
+ ### New features
125
+
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))
127
+
128
+ ## 1.6.1
129
+
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))
137
+
138
+ ## 1.6.0
139
+
140
+ ### New features
141
+
142
+ * `Config#fail_on_missing` option (default `false`) to raise a `KeyError` exception when accessing a non-existing key
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))
144
+
145
+ ## 1.5.1
146
+
147
+ ### New features
148
+
149
+ * Add parsing of ENV variable values to Boolean type ([#180](https://github.com/rubyconfig/config/pull/180))
150
+
151
+ ## 1.5.0
152
+
153
+ ### New features
154
+
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))
157
+
158
+ ### Bug fixes
159
+
160
+ * Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/rubyconfig/config/pull/177) thanks to [@rdodson41](https://github.com/rdodson41))
161
+
3
162
  ## 1.4.0
4
163
 
5
- * 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))
6
- * Added new reserved name `test` ([#158](https://github.com/railsconfig/config/pull/158) thanks to [@milushov](https://github.com/milushov))
7
- * `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))
164
+ ### New features
165
+
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))
167
+
168
+ ### Bug fixes
169
+
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))
8
172
 
9
173
  ## 1.3.0
10
174
 
11
- * **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
12
176
  * Changed default ENV variables loading settings to downcase variable names and parse values
13
177
  * Added parsing ENV variables values to Float type
14
- * 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)
15
179
 
16
180
  ## 1.2.1
17
181
 
18
- * 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))
19
183
 
20
184
  ## 1.2.0
21
185
 
22
- * 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))
23
- * 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))
24
188
 
25
189
  ## 1.1.1
26
190
 
27
- * 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))
28
192
 
29
193
  ## 1.1.0
30
194
 
@@ -33,12 +197,12 @@
33
197
 
34
198
  ## 1.0.0
35
199
 
36
- * `RailsConfig` is now officially renamed to `Config`
37
- * Fixed array descent when converting to hash ([#89](https://github.com/railsconfig/config/pull/89))
38
- * Catch OpenStruct reserved keywords ([#95](https://github.com/railsconfig/config/pull/95) by [@dudo](https://github.com/dudo))
39
- * Allows loading before app configuration process ([#107](https://github.com/railsconfig/config/pull/107) by [@Antiarchitect](https://github.com/Antiarchitect))
40
- * `deep_merge` is now properly managed via gemspec ([#110](https://github.com/railsconfig/config/pull/110))
41
- * 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))
42
206
 
43
207
  ## 0.99
44
208
 
@@ -70,6 +234,3 @@
70
234
 
71
235
  * Expose Settings in application.rb, so you don't have to duplicate configuration for each environment file ([#59](https://github.com/railsjedi/config/issues/59))
72
236
  * Adding support for Rails 4.1.0.rc ([#70](https://github.com/railsjedi/config/issues/70))
73
-
74
-
75
-
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,11 +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
- [![Code Climate](https://codeclimate.com/github/railsconfig/config/badges/gpa.svg)](https://codeclimate.com/github/railsconfig/config)
7
- [![Issue Count](https://codeclimate.com/github/railsconfig/config/badges/issue_count.svg)](https://codeclimate.com/github/railsconfig/config)
8
- [![Test Coverage](https://codeclimate.com/github/railsconfig/config/badges/coverage.svg)](https://codeclimate.com/github/railsconfig/config/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)
9
8
 
10
9
  ## Summary
11
10
 
@@ -22,16 +21,22 @@ Config helps you easily manage environment specific settings in an easy and usab
22
21
 
23
22
  ## Compatibility
24
23
 
25
- * Ruby `2.x`
26
- * Rails `>= 3.1`, `4` and `5`
27
- * Padrino
28
- * Sinatra
24
+ Current version supports and is [tested](.github/workflows/tests.yml#L19) for the following interpreters and frameworks:
29
25
 
30
- 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).
31
36
 
32
37
  ## Installing
33
38
 
34
- ### Installing on Rails 3, 4 or 5
39
+ ### Installing on Rails
35
40
 
36
41
  Add `gem 'config'` to your `Gemfile` and run `bundle install` to install it. Then run
37
42
 
@@ -40,12 +45,13 @@ Add `gem 'config'` to your `Gemfile` and run `bundle install` to install it. The
40
45
  which will generate customizable config file `config/initializers/config.rb` and set of default settings files:
41
46
 
42
47
  config/settings.yml
48
+ config/settings.local.yml
43
49
  config/settings/development.yml
44
50
  config/settings/production.yml
45
51
  config/settings/test.yml
46
52
 
47
53
  You can now edit them to adjust to your needs.
48
- a
54
+
49
55
  ### Installing on Padrino
50
56
 
51
57
  Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`
@@ -56,8 +62,7 @@ register Config
56
62
 
57
63
  ### Installing on Sinatra
58
64
 
59
- Add the gem to your `Gemfile` and run `bundle install` to install it. Afterwards in need to register `Config` in your
60
- 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.
61
66
 
62
67
  ```ruby
63
68
  set :root, File.dirname(__FILE__)
@@ -66,15 +71,13 @@ register Config
66
71
 
67
72
  ### Installing on other ruby projects
68
73
 
69
- Add the gem to your `Gemfile` and run `bundle install` to install it.
70
- 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.
71
75
 
72
76
  ```ruby
73
77
  Config.load_and_set_settings(Config.setting_files("/path/to/config_root", "your_project_environment"))
74
78
  ```
75
79
 
76
- It's also possible to initialize `Config` manually within your configure block if you want to just give it some yml
77
- 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.
78
81
 
79
82
  ```ruby
80
83
  Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
@@ -82,8 +85,7 @@ Config.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
82
85
 
83
86
  ## Accessing the Settings object
84
87
 
85
- After installing the gem, `Settings` object will become available globally and by default will be compiled from the
86
- 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.
87
89
 
88
90
  config/settings.yml
89
91
  config/settings/#{environment}.yml
@@ -135,8 +137,7 @@ Settings.reload_from_files(
135
137
 
136
138
  ### Environment specific config files
137
139
 
138
- You can have environment specific config files. Environment specific config entries take precedence over common config
139
- entries.
140
+ You can have environment specific config files. Environment specific config entries take precedence over common config entries.
140
141
 
141
142
  Example development environment config file:
142
143
 
@@ -152,8 +153,7 @@ Example production environment config file:
152
153
 
153
154
  ### Developer specific config files
154
155
 
155
- If you want to have local settings, specific to your machine or development environment,
156
- 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` :
157
157
 
158
158
  ```ruby
159
159
  Rails.root.join("config", "settings.local.yml").to_s,
@@ -161,6 +161,8 @@ Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
161
161
  Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
162
162
  ```
163
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
+
164
166
  ### Adding sources at runtime
165
167
 
166
168
  You can add new YAML config files at runtime. Just use:
@@ -179,19 +181,18 @@ Settings.prepend_source!("/path/to/source.yml")
179
181
  Settings.reload!
180
182
  ```
181
183
 
182
- This will do the same as `add_source`, but the given YML file will be loaded first (instead of last) and its settings
183
- 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.
184
185
 
185
- One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent
186
- 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
187
187
 
188
188
  ```ruby
189
189
  Settings.add_source!("#{Rails.root}/config/settings/local.yml")
190
190
  Settings.reload!
191
191
  ```
192
192
 
193
- > Note: this is an example usage, it is easier to just use the default local files `settings.local.yml,
194
- 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.
195
196
 
196
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.
197
198
 
@@ -251,18 +252,16 @@ Settings.section.servers[1].name # => amazon.com
251
252
 
252
253
  ## Configuration
253
254
 
254
- There are multiple configuration options available, however you can customize `Config` only once, preferably during
255
- application initialization phase:
255
+ There are multiple configuration options available, however you can customize `Config` only once, preferably during application initialization phase:
256
256
 
257
257
  ```ruby
258
258
  Config.setup do |config|
259
259
  config.const_name = 'Settings'
260
- ...
260
+ # ...
261
261
  end
262
262
  ```
263
263
 
264
- After installing `Config` in Rails, you will find automatically generated file that contains default configuration
265
- 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`.
266
265
 
267
266
  ### General
268
267
 
@@ -271,18 +270,139 @@ located at `config/initializers/config.rb`.
271
270
  ### Merge customization
272
271
 
273
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`
274
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`
275
+ * `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`.
276
+
277
+ ```ruby
278
+ # merge_nil_values is true by default
279
+ c = Config.load_files("./spec/fixtures/development.yml") # => #<Config::Options size=2, ...>
280
+ c.size # => 2
281
+ c.merge!(size: nil) => #<Config::Options size=nil, ...>
282
+ c.size # => nil
283
+ ```
284
+
285
+ ```ruby
286
+ # To reject nil values when merging settings:
287
+ Config.setup do |config|
288
+ config.merge_nil_values = false
289
+ end
290
+
291
+ c = Config.load_files("./spec/fixtures/development.yml") # => #<Config::Options size=2, ...>
292
+ c.size # => 2
293
+ c.merge!(size: nil) => #<Config::Options size=nil, ...>
294
+ c.size # => 2
295
+ ```
275
296
 
276
297
  Check [Deep Merge](https://github.com/danielsdeleo/deep_merge) for more details.
277
298
 
299
+ ### Validation
300
+
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):
340
+
341
+ ```ruby
342
+ Config.setup do |config|
343
+ # ...
344
+ config.schema do
345
+ optional(:email).maybe(:str?)
346
+
347
+ required(:youtube).schema do
348
+ required(:api_key).filled
349
+ end
350
+ end
351
+ end
352
+ ```
353
+
354
+ Check [dry-schema](https://github.com/dry-rb/dry-schema) for more details.
355
+
356
+ ### Missing keys
357
+
358
+ For an example settings file:
359
+
360
+ ```yaml
361
+ size: 1
362
+ server: google.com
363
+ ```
364
+
365
+ You can test if a value was set for a given key using `key?` and its alias `has_key?`:
366
+
367
+ ```ruby
368
+ Settings.key?(:path)
369
+ # => false
370
+ Settings.key?(:server)
371
+ # => true
372
+ ```
373
+
374
+ By default, accessing to a missing key returns `nil`:
375
+
376
+ ```ruby
377
+ Settings.key?(:path)
378
+ # => false
379
+ Settings.path
380
+ # => nil
381
+ ```
382
+
383
+ This is not "typo-safe". To solve this problem, you can configure the `fail_on_missing` option:
384
+
385
+ ```ruby
386
+ Config.setup do |config|
387
+ config.fail_on_missing = true
388
+ # ...
389
+ end
390
+ ```
391
+
392
+ So it will raise a `KeyError` when accessing a non-existing key (similar to `Hash#fetch` behaviour):
393
+
394
+ ```ruby
395
+ Settings.path
396
+ # => raises KeyError: key not found: :path
397
+ ```
398
+
278
399
  ### Environment variables
279
400
 
280
401
  See section below for more details.
281
402
 
282
403
  ## Working with environment variables
283
404
 
284
- To load environment variables from the `ENV` object, that will override any settings defined in files, set the `use_env`
285
- 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:
286
406
 
287
407
  ```ruby
288
408
  Config.setup do |config|
@@ -291,8 +411,7 @@ Config.setup do |config|
291
411
  end
292
412
  ```
293
413
 
294
- Now config would read values from the ENV object to the settings. For the example above it would look for keys starting
295
- 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`:
296
415
 
297
416
  ```ruby
298
417
  ENV['Settings.section.size'] = 1
@@ -301,11 +420,24 @@ ENV['Settings.section.server'] = 'google.com'
301
420
 
302
421
  It won't work with arrays, though.
303
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
+
304
438
  ### Working with Heroku
305
439
 
306
- Heroku uses ENV object to store sensitive settings. You cannot upload such files to Heroku because it's ephemeral
307
- filesystem gets recreated from the git sources on each instance refresh. To use config with Heroku just set the
308
- `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.
309
441
 
310
442
  To upload your local values to Heroku you could ran `bundle exec rake config:heroku`.
311
443
 
@@ -313,20 +445,19 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her
313
445
 
314
446
  You can customize how environment variables are processed:
315
447
 
316
- * `env_prefix` (default: `SETTINGS`) - which ENV variables to load into config
317
- * `env_separator` (default: `.`) - what string to use as level separator - default value of `.` works well with
318
- Heroku, but you might want to change it for example for `__` to easy override settings from command line, where using
319
- 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)
320
450
  * `env_converter` (default: `:downcase`) - how to process variables names:
321
451
  * `nil` - no change
322
452
  * `:downcase` - convert to lower case
323
- * `env_parse_values` (default: `true`) - try to parse values to a correct type (`Integer`, `Float`, `String`)
453
+ * `env_parse_values` (default: `true`) - try to parse values to a correct type (`Boolean`, `Integer`, `Float`, `String`)
324
454
 
325
455
  For instance, given the following environment:
326
456
 
327
457
  ```bash
328
458
  SETTINGS__SECTION__SERVER_SIZE=1
329
459
  SETTINGS__SECTION__SERVER=google.com
460
+ SETTINGS__SECTION__SSL_ENABLED=false
330
461
  ```
331
462
 
332
463
  And the following configuration:
@@ -334,7 +465,7 @@ And the following configuration:
334
465
  ```ruby
335
466
  Config.setup do |config|
336
467
  config.use_env = true
337
- config.env_prefix = 'Settings'
468
+ config.env_prefix = 'SETTINGS'
338
469
  config.env_separator = '__'
339
470
  config.env_converter = :downcase
340
471
  config.env_parse_values = true
@@ -346,28 +477,59 @@ The following settings will be available:
346
477
  ```ruby
347
478
  Settings.section.server_size # => 1
348
479
  Settings.section.server # => 'google.com'
480
+ Settings.section.ssl_enabled # => false
349
481
  ```
350
482
 
351
- ## Contributing
483
+ ### Working with AWS Secrets Manager
352
484
 
353
- 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`.
354
486
 
355
- ```bash
356
- 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
+ }
357
494
  ```
358
495
 
359
- 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.
360
497
 
361
- ```bash
362
- 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!
363
508
  ```
364
509
 
365
- If you modified any of the documentation files verify their format:
510
+ In this case, the following settings will be available:
366
511
 
367
- ```bash
368
- mdl --style .mdlstyle.rb *.md
512
+ ```ruby
513
+ Settings.foo # => "hello"
514
+ Settings.bar # => "world"
515
+ ```
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)
369
525
  ```
370
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
+
371
533
  ## Authors
372
534
 
373
535
  * [Piotr Kuczynski](http://github.com/pkuczynski)
@@ -375,6 +537,28 @@ mdl --style .mdlstyle.rb *.md
375
537
  * [Jacques Crocker](http://github.com/railsjedi)
376
538
  * Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
377
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
+
378
562
  ## License
379
563
 
380
- 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).