config 1.7.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -30
- data/CONTRIBUTING.md +32 -0
- data/README.md +103 -68
- data/config.gemspec +30 -33
- data/lib/config.rb +37 -37
- data/lib/config/configuration.rb +36 -0
- data/lib/config/integrations/rails/railtie.rb +1 -1
- data/lib/config/options.rb +15 -8
- data/lib/config/validation/error.rb +3 -14
- 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 +60 -121
- 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: fa6adc2bd8ce8b4bfbd732f11005ae7657ef8f5eb8c08b9e08d480408d344433
|
4
|
+
data.tar.gz: 48d8c6f90457636a2e1732df83cda5dfa2d2d4f5f8286bf7ceb8683f09831e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32228943bbf540ef716f788fd2cde8c51161cf7a92c3d17f36a109aadf895fde2240187f04e7be17a61488602521ee646c74bdf60657c21ad382b757fd22c203
|
7
|
+
data.tar.gz: e148e52b0f43442c9e8a36e406622d538bcdf9e2faa7eb256376d60bcf2fd8c7c0bf5890a13077a47a0d8415d908ec63567e622f948f93086181f02c653d68b8
|
data/CHANGELOG.md
CHANGED
@@ -4,88 +4,166 @@
|
|
4
4
|
|
5
5
|
...
|
6
6
|
|
7
|
+
## 2.2.2
|
8
|
+
|
9
|
+
### Bug fixes
|
10
|
+
|
11
|
+
* Added alias to_h for to_hash ([#277](https://github.com/railsconfig/config/issues/277))
|
12
|
+
* Prevent unnecessary doubled loading of environment variables ([#291](https://github.com/rubyconfig/config/pull/291))
|
13
|
+
* 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))
|
14
|
+
|
15
|
+
### Changes
|
16
|
+
|
17
|
+
* Add JRuby 9.2 to the test matrix ([#228](https://github.com/railsconfig/config/issues/228))
|
18
|
+
* Add exit! to reserved keywords ([#289](https://github.com/railsconfig/config/issues/289))
|
19
|
+
|
20
|
+
## 2.2.1
|
21
|
+
|
22
|
+
### Performance improvements
|
23
|
+
|
24
|
+
* Get rid of unused Rails Engine class definition ([#247](https://github.com/rubyconfig/config/pull/247))
|
25
|
+
* Require dry-validation only when schema is specified ([#253](https://github.com/rubyconfig/config/pull/253))
|
26
|
+
* Defer modification of `ActionController::Base` to when it is loaded in Rails integration ([#250](https://github.com/rubyconfig/config/pull/250))
|
27
|
+
|
28
|
+
### Bug fixes
|
29
|
+
|
30
|
+
* Fix missing new_ostruct_member in Ruby 2.7 ([#255](https://github.com/rubyconfig/config/pull/255))
|
31
|
+
* Fix validation contract documentation ([#260](https://github.com/rubyconfig/config/pull/260))
|
32
|
+
* Excluded test application's *.md files from the gem build ([#267](https://github.com/rubyconfig/config/pull/267))
|
33
|
+
|
34
|
+
### Changes
|
35
|
+
|
36
|
+
* Use sprockets 3.x when running unit tests for Rails 4.2 ([#256](https://github.com/rubyconfig/config/pull/256))
|
37
|
+
* Cleanup example Rails application used for testing ([#263](https://github.com/rubyconfig/config/pull/263))
|
38
|
+
* Upgrade markdown linter and fix errors ([#265](https://github.com/rubyconfig/config/pull/265))
|
39
|
+
* Upgrade development dependencies and test matrix with latest Ruby and Rails versions ([#264](https://github.com/rubyconfig/config/pull/264))
|
40
|
+
* Replace Travis CI with GitHub Actions ([#266](https://github.com/rubyconfig/config/pull/266))
|
41
|
+
* Add Rails 6.0 to the test matrix ([#258](https://github.com/rubyconfig/config/pull/258))
|
42
|
+
* Rename GitHub organization name from `railsconfig` to `rubyconfig` ([#268](https://github.com/rubyconfig/config/pull/268))
|
43
|
+
|
44
|
+
## 2.1.0
|
45
|
+
|
46
|
+
### New features
|
47
|
+
|
48
|
+
* Add dry-validation contract support ([#238](https://github.com/rubyconfig/config/pull/238))
|
49
|
+
|
50
|
+
### Changes
|
51
|
+
|
52
|
+
* Get rid of activesupport dependency ([#230](https://github.com/rubyconfig/config/pull/230))
|
53
|
+
* Ignore .local files in test environment ([#135](https://github.com/rubyconfig/config/issues/135), [#233](https://github.com/rubyconfig/config/pull/233))
|
54
|
+
* Execute default rspec against latest Rails app and load appropriate development dependencies dynamically ([#241](https://github.com/rubyconfig/config/pull/241))
|
55
|
+
* Fix inconsistent documentation for ENV prefix and default value in generator ([#246](https://github.com/rubyconfig/config/pull/246))
|
56
|
+
|
57
|
+
### Bug fixes
|
58
|
+
|
59
|
+
* Fix warnings when running tests in Rails 5 scope ([#240](https://github.com/rubyconfig/config/issues/240)
|
60
|
+
* Do not run incompatible code coverage on truffleruby ([#242](https://github.com/rubyconfig/config/issues/242)
|
61
|
+
|
62
|
+
## 2.0.0
|
63
|
+
|
64
|
+
### BREAKING CHANGES
|
65
|
+
|
66
|
+
After upgrade to dry-schema 1.0 we had to drop support for Rails `< 4.2` and Ruby `< 2.4`.
|
67
|
+
If you need older version of Ruby or Rails, please stick to 1.x version of this gem.
|
68
|
+
|
69
|
+
### New features
|
70
|
+
|
71
|
+
* Add `merge_hash_arrays` as a configuration option ([#214](https://github.com/rubyconfig/config/pull/214))
|
72
|
+
|
73
|
+
### Changes
|
74
|
+
|
75
|
+
* Upgraded dry-validation dependency to dry-schema 1.0 ([#224](https://github.com/rubyconfig/config/pull/224))
|
76
|
+
* Moved constant to be defined on `Object` instead of `Kernel` ([#227](https://github.com/rubyconfig/config/issues/227))
|
77
|
+
* Add TruffleRuby to the test matrix ([#229](https://github.com/rubyconfig/config/issues/229))
|
78
|
+
|
79
|
+
## 1.7.2
|
80
|
+
|
81
|
+
### Bug fixes
|
82
|
+
|
83
|
+
* Lock max version of dry-validation depending on the ruby version ([#223](https://github.com/rubyconfig/config/pull/223))
|
84
|
+
|
7
85
|
## 1.7.1
|
8
86
|
|
9
87
|
### New features
|
10
88
|
|
11
|
-
* Upgrade dependencies ([#211](https://github.com/
|
89
|
+
* Upgrade dependencies ([#211](https://github.com/rubyconfig/config/pull/211))
|
12
90
|
|
13
91
|
### Changes
|
14
92
|
|
15
|
-
* Add Ruby 2.5 and Rails 5.1 to the testing matrix on Travis ([#201](https://github.com/
|
16
|
-
* Add Ruby 2.6
|
17
|
-
* Add Rails 5.2 to the test matrix ([#212](https://github.com/
|
93
|
+
* Add Ruby 2.5 and Rails 5.1 to the testing matrix on Travis ([#201](https://github.com/rubyconfig/config/pull/201))
|
94
|
+
* Add Ruby 2.6 to the test matrix ([#210](https://github.com/rubyconfig/config/pull/210))
|
95
|
+
* Add Rails 5.2 to the test matrix ([#212](https://github.com/rubyconfig/config/pull/212))
|
18
96
|
|
19
97
|
## 1.7.0
|
20
98
|
|
21
99
|
### New features
|
22
100
|
|
23
|
-
* **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/
|
101
|
+
* **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))
|
24
102
|
|
25
103
|
## 1.6.1
|
26
104
|
|
27
105
|
### Bug fixes
|
28
106
|
|
29
|
-
* Make dry-validation dependency less strict allowing to use newer versions ([#183](https://github.com/
|
30
|
-
* Fix `key?` and `has_key?`, which raise NoMethodError in non Rails environment, by using ActiveSupport `#delegate` implicitly ([#185](https://github.com/
|
31
|
-
* Update `deep_merge` dependency to latest version (v1.2.1) ([#191](https://github.com/
|
32
|
-
* Upgrade `rubocop` to version 0.52.1 ([#193](https://github.com/
|
33
|
-
* Add `zip` to the list of reserved keywords ([#197](https://github.com/
|
107
|
+
* Make dry-validation dependency less strict allowing to use newer versions ([#183](https://github.com/rubyconfig/config/pull/183))
|
108
|
+
* 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))
|
109
|
+
* Update `deep_merge` dependency to latest version (v1.2.1) ([#191](https://github.com/rubyconfig/config/pull/191))
|
110
|
+
* Upgrade `rubocop` to version 0.52.1 ([#193](https://github.com/rubyconfig/config/pull/193))
|
111
|
+
* Add `zip` to the list of reserved keywords ([#197](https://github.com/rubyconfig/config/pull/197))
|
34
112
|
|
35
113
|
## 1.6.0
|
36
114
|
|
37
115
|
### New features
|
38
116
|
|
39
117
|
* `Config#fail_on_missing` option (default `false`) to raise a `KeyError` exception when accessing a non-existing key
|
40
|
-
* Add ability to test if a value was set for a given key with `key?` and `has_key?` ([#182](https://github.com/
|
118
|
+
* 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))
|
41
119
|
|
42
120
|
## 1.5.1
|
43
121
|
|
44
122
|
### New features
|
45
123
|
|
46
|
-
* Add parsing of ENV variable values to Boolean type ([#180](https://github.com/
|
124
|
+
* Add parsing of ENV variable values to Boolean type ([#180](https://github.com/rubyconfig/config/pull/180))
|
47
125
|
|
48
126
|
## 1.5.0
|
49
127
|
|
50
128
|
### New features
|
51
129
|
|
52
|
-
* Add ability to validate config schema ([#155](https://github.com/
|
53
|
-
* Add count to the reserved names list ([#167](https://github.com/
|
130
|
+
* Add ability to validate config schema ([#155](https://github.com/rubyconfig/config/pull/155) thanks to [@ok32](https://github.com/ok32))
|
131
|
+
* Add count to the reserved names list ([#167](https://github.com/rubyconfig/config/pull/167) thanks to [@carbonin](https://github.com/carbonin))
|
54
132
|
|
55
133
|
### Bug fixes
|
56
134
|
|
57
|
-
* Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/
|
135
|
+
* Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/rubyconfig/config/pull/177) thanks to [@rdodson41](https://github.com/rdodson41))
|
58
136
|
|
59
137
|
## 1.4.0
|
60
138
|
|
61
139
|
### New features
|
62
140
|
|
63
|
-
* Added support for passing a raw ruby hash into to both `Settings.add_source!` and `Settings.prepend_source!` ([#108](https://github.com/
|
141
|
+
* 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))
|
64
142
|
|
65
143
|
### Bug fixes
|
66
144
|
|
67
|
-
* Added new reserved name `test` ([#158](https://github.com/
|
68
|
-
* `to_hash` should not replace nested config objects with Hash ([#160](https://github.com/
|
145
|
+
* Added new reserved name `test` ([#158](https://github.com/rubyconfig/config/pull/158) thanks to [@milushov](https://github.com/milushov))
|
146
|
+
* `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))
|
69
147
|
|
70
148
|
## 1.3.0
|
71
149
|
|
72
|
-
* **WARNING:** Overwrite arrays found in previously loaded settings file ([#137](https://github.com/
|
150
|
+
* **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
|
73
151
|
* Changed default ENV variables loading settings to downcase variable names and parse values
|
74
152
|
* Added parsing ENV variables values to Float type
|
75
|
-
* 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/
|
153
|
+
* 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)
|
76
154
|
|
77
155
|
## 1.2.1
|
78
156
|
|
79
|
-
* Fixed support for multilevel settings loaded from ENV variables (inspired by [@cbeer](https://github.com/cbeer) in [#144](https://github.com/
|
157
|
+
* 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))
|
80
158
|
|
81
159
|
## 1.2.0
|
82
160
|
|
83
|
-
* Add ability to load settings from ENV variables ([#108](https://github.com/
|
84
|
-
* Removed Rails 5 deprecation warnings for prepend_before_filter ([#141](https://github.com/
|
161
|
+
* 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))
|
162
|
+
* Removed Rails 5 deprecation warnings for prepend_before_filter ([#141](https://github.com/rubyconfig/config/pull/141))
|
85
163
|
|
86
164
|
## 1.1.1
|
87
165
|
|
88
|
-
* Downgrade minimum ruby version to 2.0.0 ([#136](https://github.com/
|
166
|
+
* Downgrade minimum ruby version to 2.0.0 ([#136](https://github.com/rubyconfig/config/issues/136))
|
89
167
|
|
90
168
|
## 1.1.0
|
91
169
|
|
@@ -94,12 +172,12 @@
|
|
94
172
|
|
95
173
|
## 1.0.0
|
96
174
|
|
97
|
-
* `
|
98
|
-
* Fixed array descent when converting to hash ([#89](https://github.com/
|
99
|
-
* Catch OpenStruct reserved keywords ([#95](https://github.com/
|
100
|
-
* Allows loading before app configuration process ([#107](https://github.com/
|
101
|
-
* `deep_merge` is now properly managed via gemspec ([#110](https://github.com/
|
102
|
-
* Added `prepend_source!` ([#102](https://github.com/
|
175
|
+
* `rubyconfig` is now officially renamed to `Config`
|
176
|
+
* Fixed array descent when converting to hash ([#89](https://github.com/rubyconfig/config/pull/89))
|
177
|
+
* Catch OpenStruct reserved keywords ([#95](https://github.com/rubyconfig/config/pull/95) by [@dudo](https://github.com/dudo))
|
178
|
+
* Allows loading before app configuration process ([#107](https://github.com/rubyconfig/config/pull/107) by [@Antiarchitect](https://github.com/Antiarchitect))
|
179
|
+
* `deep_merge` is now properly managed via gemspec ([#110](https://github.com/rubyconfig/config/pull/110))
|
180
|
+
* Added `prepend_source!` ([#102](https://github.com/rubyconfig/config/pull/102))
|
103
181
|
|
104
182
|
## 0.99
|
105
183
|
|
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
3
|
[![Gem Version](https://badge.fury.io/rb/config.svg)](http://badge.fury.io/rb/config)
|
5
|
-
[![
|
6
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/maintainability)](https://codeclimate.com/github/
|
7
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/test_coverage)](https://codeclimate.com/github/
|
4
|
+
[![Tests](https://github.com/rubyconfig/config/workflows/tests/badge.svg)](https://github.com/rubyconfig/config/actions?query=branch%3Amaster)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/maintainability)](https://codeclimate.com/github/rubyconfig/config/maintainability)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/85c206c13dce7de090af/test_coverage)](https://codeclimate.com/github/rubyconfig/config/test_coverage)
|
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
|
-
|
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
|
-
|
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
|
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,11 +181,9 @@ 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")
|
@@ -250,18 +251,16 @@ Settings.section.servers[1].name # => amazon.com
|
|
250
251
|
|
251
252
|
## Configuration
|
252
253
|
|
253
|
-
There are multiple configuration options available, however you can customize `Config` only once, preferably during
|
254
|
-
application initialization phase:
|
254
|
+
There are multiple configuration options available, however you can customize `Config` only once, preferably during application initialization phase:
|
255
255
|
|
256
256
|
```ruby
|
257
257
|
Config.setup do |config|
|
258
258
|
config.const_name = 'Settings'
|
259
|
-
...
|
259
|
+
# ...
|
260
260
|
end
|
261
261
|
```
|
262
262
|
|
263
|
-
After installing `Config` in Rails, you will find automatically generated file that contains default configuration
|
264
|
-
located at `config/initializers/config.rb`.
|
263
|
+
After installing `Config` in Rails, you will find automatically generated file that contains default configuration located at `config/initializers/config.rb`.
|
265
264
|
|
266
265
|
### General
|
267
266
|
|
@@ -270,6 +269,7 @@ located at `config/initializers/config.rb`.
|
|
270
269
|
### Merge customization
|
271
270
|
|
272
271
|
* `overwrite_arrays` - overwrite arrays found in previously loaded settings file. Default: `true`
|
272
|
+
* `merge_hash_arrays` - merge hashes inside of arrays from previously loaded settings files. Makes sense only when `overwrite_arrays = false`. Default: `false`
|
273
273
|
* `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
274
|
* `merge_nil_values` - `nil` values will overwrite an existing value when merging configs. Default: `true`.
|
275
275
|
|
@@ -297,12 +297,52 @@ Check [Deep Merge](https://github.com/danielsdeleo/deep_merge) for more details.
|
|
297
297
|
|
298
298
|
### Validation
|
299
299
|
|
300
|
-
With Ruby 2.1 or newer, you can optionally define a schema to validate presence (and type) of specific config values
|
300
|
+
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.
|
301
|
+
|
302
|
+
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.
|
303
|
+
|
304
|
+
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.
|
305
|
+
|
306
|
+
#### Contract
|
307
|
+
|
308
|
+
Leverage dry-validation, you can create a contract with a params schema and rules:
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
class ConfigContract < Dry::Validation::Contract
|
312
|
+
params do
|
313
|
+
optional(:email).maybe(:str?)
|
314
|
+
|
315
|
+
required(:youtube).schema do
|
316
|
+
required(:api_key).filled
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
rule(:email) do
|
321
|
+
unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
|
322
|
+
key.failure('has invalid format')
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
Config.setup do |config|
|
328
|
+
config.validation_contract = ConfigContract.new
|
329
|
+
end
|
330
|
+
```
|
331
|
+
|
332
|
+
The above example adds a rule to ensure the `email` is valid by matching it against the provided regular expression.
|
333
|
+
|
334
|
+
Check [dry-validation](https://github.com/dry-rb/dry-validation) for more details.
|
335
|
+
|
336
|
+
#### Schema
|
337
|
+
|
338
|
+
You may also specify a schema using [dry-schema](https://github.com/dry-rb/dry-schema):
|
301
339
|
|
302
340
|
```ruby
|
303
341
|
Config.setup do |config|
|
304
342
|
# ...
|
305
343
|
config.schema do
|
344
|
+
optional(:email).maybe(:str?)
|
345
|
+
|
306
346
|
required(:youtube).schema do
|
307
347
|
required(:api_key).filled
|
308
348
|
end
|
@@ -310,14 +350,7 @@ Config.setup do |config|
|
|
310
350
|
end
|
311
351
|
```
|
312
352
|
|
313
|
-
|
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.
|
353
|
+
Check [dry-schema](https://github.com/dry-rb/dry-schema) for more details.
|
321
354
|
|
322
355
|
### Missing keys
|
323
356
|
|
@@ -368,8 +401,7 @@ See section below for more details.
|
|
368
401
|
|
369
402
|
## Working with environment variables
|
370
403
|
|
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:
|
404
|
+
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
405
|
|
374
406
|
```ruby
|
375
407
|
Config.setup do |config|
|
@@ -378,8 +410,7 @@ Config.setup do |config|
|
|
378
410
|
end
|
379
411
|
```
|
380
412
|
|
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`:
|
413
|
+
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
414
|
|
384
415
|
```ruby
|
385
416
|
ENV['Settings.section.size'] = 1
|
@@ -390,9 +421,7 @@ It won't work with arrays, though.
|
|
390
421
|
|
391
422
|
### Working with Heroku
|
392
423
|
|
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.
|
424
|
+
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
425
|
|
397
426
|
To upload your local values to Heroku you could ran `bundle exec rake config:heroku`.
|
398
427
|
|
@@ -400,10 +429,8 @@ To upload your local values to Heroku you could ran `bundle exec rake config:her
|
|
400
429
|
|
401
430
|
You can customize how environment variables are processed:
|
402
431
|
|
403
|
-
* `env_prefix` (default: `
|
404
|
-
* `env_separator` (default:
|
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)
|
432
|
+
* `env_prefix` (default: `const_name`) - load only ENV variables starting with this prefix (case-sensitive)
|
433
|
+
* `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
434
|
* `env_converter` (default: `:downcase`) - how to process variables names:
|
408
435
|
* `nil` - no change
|
409
436
|
* `:downcase` - convert to lower case
|
@@ -439,23 +466,9 @@ Settings.section.ssl_enabled # => false
|
|
439
466
|
|
440
467
|
## Contributing
|
441
468
|
|
442
|
-
|
443
|
-
|
444
|
-
```bash
|
445
|
-
appraisal install
|
446
|
-
```
|
447
|
-
|
448
|
-
Run the test suite:
|
449
|
-
|
450
|
-
```bash
|
451
|
-
appraisal rspec
|
452
|
-
```
|
453
|
-
|
454
|
-
If you modified any of the documentation files verify their format:
|
469
|
+
You are very warmly welcome to help. Please follow our [contribution guidelines](CONTRIBUTING.md)
|
455
470
|
|
456
|
-
|
457
|
-
mdl --style .mdlstyle.rb *.md
|
458
|
-
```
|
471
|
+
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.
|
459
472
|
|
460
473
|
## Authors
|
461
474
|
|
@@ -464,6 +477,28 @@ mdl --style .mdlstyle.rb *.md
|
|
464
477
|
* [Jacques Crocker](http://github.com/railsjedi)
|
465
478
|
* Inherited from [AppConfig](http://github.com/cjbottaro/app_config) by [Christopher J. Bottaro](http://github.com/cjbottaro)
|
466
479
|
|
480
|
+
## Contributors
|
481
|
+
|
482
|
+
### Code Contributors
|
483
|
+
|
484
|
+
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).
|
485
|
+
|
486
|
+
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.
|
487
|
+
|
488
|
+
[![Contributors](https://opencollective.com/rubyconfig/contributors.svg?width=890&button=false)](https://github.com/rubyconfig/config/graphs/contributors)
|
489
|
+
|
490
|
+
### Financial Contributors
|
491
|
+
|
492
|
+
[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! 🙏
|
493
|
+
|
494
|
+
[![Backers](https://opencollective.com/rubyconfig/backers.svg?width=890)](https://opencollective.com/rubyconfig)
|
495
|
+
|
496
|
+
#### Sponsors
|
497
|
+
|
498
|
+
Support this project by becoming a [sponsor](https://opencollective.com/rubyconfig#sponsor). Your logo will show up here with a link to your website.
|
499
|
+
|
500
|
+
[![Sponsors](https://opencollective.com/rubyconfig/sponsors.svg?width=890)](https://opencollective.com/rubyconfig)
|
501
|
+
|
467
502
|
## License
|
468
503
|
|
469
|
-
|
504
|
+
Copyright (C) Piotr Kuczynski. Released under the [MIT License](LICENSE.md).
|