config 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +26 -2
- data/config.gemspec +7 -5
- data/lib/config.rb +3 -0
- data/lib/config/options.rb +9 -3
- data/lib/config/validation/error.rb +24 -0
- data/lib/config/validation/schema.rb +21 -0
- data/lib/config/validation/validate.rb +19 -0
- data/lib/config/version.rb +1 -1
- data/lib/generators/config/templates/config.rb +9 -0
- metadata +31 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b6ae90fa7f141cfc8e3f6eff8f1434a108f2b99
|
4
|
+
data.tar.gz: b41fb4da0c7de1352f9f192c8fcebc7a6e53382a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e65ffa447a2e2fb94fd0941dbbc8ad4034bec9bdf1a5509224f69f3c927dedb10d7d36f9ca41fe1f452e4e5adc9def529eade2b6a6248570ae9ac92c3fa7afdd
|
7
|
+
data.tar.gz: eabc5a9851556abd9d30b07496b4f3e3fb00108a6d29e3868dcc32004f62368a9d32348beeb211d1425a44d931689cf389116b81cf4f259a6a52aa67a28012d8
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,30 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Unreleased
|
4
|
+
|
5
|
+
...
|
6
|
+
|
7
|
+
## 1.5.0
|
8
|
+
|
9
|
+
### New features
|
10
|
+
* Add ability to validate config schema ([#155](https://github.com/railsconfig/config/pull/155) thanks to [@ok32](https://github.com/ok32))
|
11
|
+
* Add count to the reserved names list ([#167](https://github.com/railsconfig/config/pull/167) thanks to [@carbonin](https://github.com/carbonin))
|
12
|
+
|
13
|
+
### Bug fixes
|
14
|
+
* Correctly parse `env_prefix`, which contains `env_separator` ([#177](https://github.com/railsconfig/config/pull/177) thanks to [@rdodson41](https://github.com/rdodson41))
|
15
|
+
|
3
16
|
## 1.4.0
|
4
17
|
|
18
|
+
### New features
|
5
19
|
* 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))
|
20
|
+
|
21
|
+
### Bug fixes
|
6
22
|
* Added new reserved name `test` ([#158](https://github.com/railsconfig/config/pull/158) thanks to [@milushov](https://github.com/milushov))
|
7
23
|
* `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))
|
8
24
|
|
9
25
|
## 1.3.0
|
10
26
|
|
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
|
27
|
+
* **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
|
12
28
|
* Changed default ENV variables loading settings to downcase variable names and parse values
|
13
29
|
* Added parsing ENV variables values to Float type
|
14
30
|
* 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)
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ which will generate customizable config file `config/initializers/config.rb` and
|
|
45
45
|
config/settings/test.yml
|
46
46
|
|
47
47
|
You can now edit them to adjust to your needs.
|
48
|
-
|
48
|
+
|
49
49
|
### Installing on Padrino
|
50
50
|
|
51
51
|
Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`
|
@@ -275,6 +275,30 @@ located at `config/initializers/config.rb`.
|
|
275
275
|
|
276
276
|
Check [Deep Merge](https://github.com/danielsdeleo/deep_merge) for more details.
|
277
277
|
|
278
|
+
### Validation
|
279
|
+
|
280
|
+
With Ruby 2.1 or newer, you can optionally define a schema to validate presence (and type) of specific config values:
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
Config.setup do |config|
|
284
|
+
# ...
|
285
|
+
config.schema do
|
286
|
+
required(:youtube).schema do
|
287
|
+
required(:api_key).filled
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
```
|
292
|
+
|
293
|
+
The above example demonstrates how to ensure that the configuration has the `youtube` structure
|
294
|
+
with the `api_key` field filled.
|
295
|
+
|
296
|
+
If you define a schema it will automatically be used to validate your config. If validation fails it will
|
297
|
+
raise a `Config::Validation::Error` containing a nice message with information about all the mismatches
|
298
|
+
between the schema and your config.
|
299
|
+
|
300
|
+
Check [dry-validation](https://github.com/dry-rb/dry-validation) for more details.
|
301
|
+
|
278
302
|
### Environment variables
|
279
303
|
|
280
304
|
See section below for more details.
|
@@ -334,7 +358,7 @@ And the following configuration:
|
|
334
358
|
```ruby
|
335
359
|
Config.setup do |config|
|
336
360
|
config.use_env = true
|
337
|
-
config.env_prefix = '
|
361
|
+
config.env_prefix = 'SETTINGS'
|
338
362
|
config.env_separator = '__'
|
339
363
|
config.env_converter = :downcase
|
340
364
|
config.env_parse_values = true
|
data/config.gemspec
CHANGED
@@ -26,13 +26,14 @@ Gem::Specification.new do |s|
|
|
26
26
|
|
27
27
|
s.add_dependency 'activesupport', '>= 3.0'
|
28
28
|
s.add_dependency 'deep_merge', '~> 1.1.1'
|
29
|
+
s.add_dependency 'dry-validation', '~> 0.10.4' if RUBY_VERSION >= '2.1'
|
29
30
|
|
30
|
-
s.add_development_dependency 'bundler', '~> 1.13', '>= 1.13.
|
31
|
-
s.add_development_dependency 'rake', '~>
|
31
|
+
s.add_development_dependency 'bundler', '~> 1.13', '>= 1.13.6'
|
32
|
+
s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
|
32
33
|
|
33
34
|
# Testing
|
34
35
|
s.add_development_dependency 'appraisal', '~> 2.1', '>= 2.1.0'
|
35
|
-
s.add_development_dependency 'rails', '~> 5.0', '>= 5.0.
|
36
|
+
s.add_development_dependency 'rails', '~> 5.0', '>= 5.0.1'
|
36
37
|
s.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
|
37
38
|
s.add_development_dependency 'rspec-rails', '~> 3.5', '>= 3.5.2'
|
38
39
|
s.add_development_dependency 'test-unit', '~> 3.2', '>= 3.2.1'
|
@@ -40,9 +41,10 @@ Gem::Specification.new do |s|
|
|
40
41
|
|
41
42
|
# Static code analysis
|
42
43
|
s.add_development_dependency 'mdl', '~> 0.4', '>= 0.4.0'
|
43
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
44
|
+
s.add_development_dependency 'rubocop', '~> 0.46', '>= 0.46.0'
|
44
45
|
|
45
46
|
if ENV['TRAVIS']
|
46
|
-
s.add_development_dependency '
|
47
|
+
s.add_development_dependency 'simplecov', '~> 0.12.0'
|
48
|
+
s.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.3'
|
47
49
|
end
|
48
50
|
end
|
data/lib/config.rb
CHANGED
@@ -6,9 +6,12 @@ require 'config/version'
|
|
6
6
|
require 'config/integrations/rails/engine' if defined?(::Rails)
|
7
7
|
require 'config/sources/yaml_source'
|
8
8
|
require 'config/sources/hash_source'
|
9
|
+
require 'config/validation/schema' if RUBY_VERSION >= '2.1'
|
9
10
|
require 'deep_merge'
|
10
11
|
|
11
12
|
module Config
|
13
|
+
extend Config::Validation::Schema if RUBY_VERSION >= '2.1'
|
14
|
+
|
12
15
|
# Ensures the setup only gets run once
|
13
16
|
@@_ran_once = false
|
14
17
|
|
data/lib/config/options.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'ostruct'
|
2
|
+
require 'config/validation/validate' if RUBY_VERSION >= '2.1'
|
2
3
|
|
3
4
|
module Config
|
4
5
|
class Options < OpenStruct
|
5
6
|
include Enumerable
|
7
|
+
include Validation::Validate if RUBY_VERSION >= '2.1'
|
6
8
|
|
7
9
|
def keys
|
8
10
|
marshal_dump.keys
|
@@ -35,9 +37,12 @@ module Config
|
|
35
37
|
hash = Hash.new
|
36
38
|
|
37
39
|
ENV.each do |variable, value|
|
38
|
-
|
40
|
+
separator = Config.env_separator
|
41
|
+
prefix = (Config.env_prefix || Config.const_name).to_s.split(separator)
|
39
42
|
|
40
|
-
|
43
|
+
keys = variable.to_s.split(separator)
|
44
|
+
|
45
|
+
next if keys.shift(prefix.size) != prefix
|
41
46
|
|
42
47
|
keys.map! { |key|
|
43
48
|
case Config.env_converter
|
@@ -83,6 +88,7 @@ module Config
|
|
83
88
|
marshal_load(__convert(conf).marshal_dump)
|
84
89
|
|
85
90
|
reload_env! if Config.use_env
|
91
|
+
validate! if RUBY_VERSION >= '2.1'
|
86
92
|
|
87
93
|
self
|
88
94
|
end
|
@@ -128,7 +134,7 @@ module Config
|
|
128
134
|
end
|
129
135
|
|
130
136
|
# Some keywords that don't play nicely with OpenStruct
|
131
|
-
SETTINGS_RESERVED_NAMES = %w{select collect test}
|
137
|
+
SETTINGS_RESERVED_NAMES = %w{select collect test count}
|
132
138
|
|
133
139
|
# An alternative mechanism for property access.
|
134
140
|
# This let's you do foo['bar'] along with foo.bar.
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Config
|
2
|
+
module Validation
|
3
|
+
class Error < StandardError
|
4
|
+
|
5
|
+
def self.format(v_res)
|
6
|
+
flatten_hash(v_res.messages).map do |field, msgs|
|
7
|
+
"#{' ' * 2}#{field}: #{msgs.join('; ')}"
|
8
|
+
end.join('\n')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.flatten_hash(h, acc={}, pref=[])
|
12
|
+
h.inject(acc) do |a, (k, v)|
|
13
|
+
if v.is_a?(Hash)
|
14
|
+
flatten_hash(v, acc, pref + [k])
|
15
|
+
else
|
16
|
+
acc[(pref + [k]).join('.')] = v
|
17
|
+
acc
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'dry-validation'
|
2
|
+
require 'config/validation/schema'
|
3
|
+
|
4
|
+
module Config
|
5
|
+
module Validation
|
6
|
+
module Schema
|
7
|
+
|
8
|
+
mattr_writer :schema
|
9
|
+
@@schema = nil
|
10
|
+
|
11
|
+
def schema(&block)
|
12
|
+
if block_given?
|
13
|
+
@@schema = Dry::Validation.Schema(&block)
|
14
|
+
else
|
15
|
+
@@schema
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'config/validation/error'
|
2
|
+
|
3
|
+
module Config
|
4
|
+
module Validation
|
5
|
+
module Validate
|
6
|
+
|
7
|
+
def validate!
|
8
|
+
if Config.schema
|
9
|
+
v_res = Config.schema.(self.to_hash)
|
10
|
+
|
11
|
+
unless v_res.success?
|
12
|
+
raise Config::Validation::Error.new("Config validation failed:\n\n#{Config::Validation::Error.format(v_res)}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/config/version.rb
CHANGED
@@ -33,4 +33,13 @@ Config.setup do |config|
|
|
33
33
|
# Parse numeric values as integers instead of strings.
|
34
34
|
#
|
35
35
|
# config.env_parse_values = true
|
36
|
+
|
37
|
+
# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
|
38
|
+
#
|
39
|
+
# config.schema do
|
40
|
+
# required(:name).filled
|
41
|
+
# required(:age).maybe(:int?)
|
42
|
+
# required(:email).filled(format?: EMAIL_REGEX)
|
43
|
+
# end
|
44
|
+
|
36
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Kuczynski
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-10-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.1.1
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: dry-validation
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.10.4
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.10.4
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: bundler
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
@@ -49,7 +63,7 @@ dependencies:
|
|
49
63
|
version: '1.13'
|
50
64
|
- - ">="
|
51
65
|
- !ruby/object:Gem::Version
|
52
|
-
version: 1.13.
|
66
|
+
version: 1.13.6
|
53
67
|
type: :development
|
54
68
|
prerelease: false
|
55
69
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -59,27 +73,27 @@ dependencies:
|
|
59
73
|
version: '1.13'
|
60
74
|
- - ">="
|
61
75
|
- !ruby/object:Gem::Version
|
62
|
-
version: 1.13.
|
76
|
+
version: 1.13.6
|
63
77
|
- !ruby/object:Gem::Dependency
|
64
78
|
name: rake
|
65
79
|
requirement: !ruby/object:Gem::Requirement
|
66
80
|
requirements:
|
67
81
|
- - "~>"
|
68
82
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
83
|
+
version: '12.0'
|
70
84
|
- - ">="
|
71
85
|
- !ruby/object:Gem::Version
|
72
|
-
version:
|
86
|
+
version: 12.0.0
|
73
87
|
type: :development
|
74
88
|
prerelease: false
|
75
89
|
version_requirements: !ruby/object:Gem::Requirement
|
76
90
|
requirements:
|
77
91
|
- - "~>"
|
78
92
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
93
|
+
version: '12.0'
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 12.0.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: appraisal
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
version: '5.0'
|
110
124
|
- - ">="
|
111
125
|
- !ruby/object:Gem::Version
|
112
|
-
version: 5.0.
|
126
|
+
version: 5.0.1
|
113
127
|
type: :development
|
114
128
|
prerelease: false
|
115
129
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -119,7 +133,7 @@ dependencies:
|
|
119
133
|
version: '5.0'
|
120
134
|
- - ">="
|
121
135
|
- !ruby/object:Gem::Version
|
122
|
-
version: 5.0.
|
136
|
+
version: 5.0.1
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
138
|
name: rspec
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,20 +240,20 @@ dependencies:
|
|
226
240
|
requirements:
|
227
241
|
- - "~>"
|
228
242
|
- !ruby/object:Gem::Version
|
229
|
-
version: '0.
|
243
|
+
version: '0.46'
|
230
244
|
- - ">="
|
231
245
|
- !ruby/object:Gem::Version
|
232
|
-
version: 0.
|
246
|
+
version: 0.46.0
|
233
247
|
type: :development
|
234
248
|
prerelease: false
|
235
249
|
version_requirements: !ruby/object:Gem::Requirement
|
236
250
|
requirements:
|
237
251
|
- - "~>"
|
238
252
|
- !ruby/object:Gem::Version
|
239
|
-
version: '0.
|
253
|
+
version: '0.46'
|
240
254
|
- - ">="
|
241
255
|
- !ruby/object:Gem::Version
|
242
|
-
version: 0.
|
256
|
+
version: 0.46.0
|
243
257
|
description: 'Easiest way to manage multi-environment settings in any ruby project
|
244
258
|
or framework: Rails, Sinatra, Pandrino and others'
|
245
259
|
email:
|
@@ -268,6 +282,9 @@ files:
|
|
268
282
|
- lib/config/sources/hash_source.rb
|
269
283
|
- lib/config/sources/yaml_source.rb
|
270
284
|
- lib/config/tasks/heroku.rake
|
285
|
+
- lib/config/validation/error.rb
|
286
|
+
- lib/config/validation/schema.rb
|
287
|
+
- lib/config/validation/validate.rb
|
271
288
|
- lib/config/version.rb
|
272
289
|
- lib/generators/config/install_generator.rb
|
273
290
|
- lib/generators/config/templates/config.rb
|