mixlib-config 2.2.5 → 2.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -2
- data/lib/mixlib/config/version.rb +1 -1
- data/lib/mixlib/config.rb +7 -0
- data/mixlib-config.gemspec +2 -0
- data/spec/mixlib/config_spec.rb +27 -5
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df81f1268299346629241aff765fad4fcb4e458fe9eaa810a187a6dd1397b3d5
|
4
|
+
data.tar.gz: 1fb4968f38fef4c1f8b78baf4e9516e8295803b68778eb259698db4b094d998e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0576c33521eafd4f4a3db47704536c491da50f98ca3052fcbba06e28cbf87d8f865ddee060694e4931e7369e7250bf70793c78362e9ca3d29b6f1aee4c12007
|
7
|
+
data.tar.gz: 46d0dcb314b8840048d16692fedec257a7871fcd9ff2b2859fa888af35c602e0e25a63d6f2a21f1b4cee36b5825d0b001e3a745a31f2484d63e626566120225e
|
data/README.md
CHANGED
@@ -43,11 +43,12 @@ And you can modify configuration values with this syntax:
|
|
43
43
|
MyConfig[:first_value] = 'foobar' # sets first_value to 'foobar'
|
44
44
|
```
|
45
45
|
|
46
|
-
If you prefer to allow your users to pass in configuration via YAML or
|
46
|
+
If you prefer to allow your users to pass in configuration via YAML, JSON or TOML files, `mixlib-config` supports that too!
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
MyConfig.from_file('~/.myconfig.yml')
|
50
50
|
MyConfig.from_file('~/.myconfig.json')
|
51
|
+
MyConfig.from_file('~/.myconfig.toml')
|
51
52
|
```
|
52
53
|
|
53
54
|
This way, a user could write a YAML config file that looked like this:
|
@@ -67,6 +68,13 @@ or a JSON file that looks like this:
|
|
67
68
|
}
|
68
69
|
```
|
69
70
|
|
71
|
+
or a TOML file that looks like this:
|
72
|
+
|
73
|
+
```toml
|
74
|
+
first_value = "hi"
|
75
|
+
second_value = "goodbye"
|
76
|
+
```
|
77
|
+
|
70
78
|
Please note: There is an inherent limitation in the logic you can do with YAML and JSON file. At this time, `mixlib-config` does not support ERB or other logic in YAML or JSON config (read "static content only").
|
71
79
|
|
72
80
|
## Nested Configuration
|
@@ -294,4 +302,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
294
302
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
295
303
|
See the License for the specific language governing permissions and
|
296
304
|
limitations under the License.
|
297
|
-
|
data/lib/mixlib/config.rb
CHANGED
@@ -57,6 +57,8 @@ module Mixlib
|
|
57
57
|
from_yaml(filename)
|
58
58
|
elsif File.extname(filename) == ".json"
|
59
59
|
from_json(filename)
|
60
|
+
elsif File.extname(filename) == ".toml"
|
61
|
+
from_toml(filename)
|
60
62
|
else
|
61
63
|
instance_eval(IO.read(filename), filename, 1)
|
62
64
|
end
|
@@ -80,6 +82,11 @@ module Mixlib
|
|
80
82
|
from_hash(JSON.parse(IO.read(filename)), filename)
|
81
83
|
end
|
82
84
|
|
85
|
+
def from_toml(filename)
|
86
|
+
require "tomlrb"
|
87
|
+
from_hash(Tomlrb.parse(IO.read(filename), symbolize_keys: true))
|
88
|
+
end
|
89
|
+
|
83
90
|
# Transforms a Hash into method-style configuration syntax to be processed
|
84
91
|
#
|
85
92
|
# === Parameters
|
data/mixlib-config.gemspec
CHANGED
data/spec/mixlib/config_spec.rb
CHANGED
@@ -759,8 +759,8 @@ describe Mixlib::Config do
|
|
759
759
|
x 10
|
760
760
|
y 20
|
761
761
|
end
|
762
|
-
@klass.blah.x.
|
763
|
-
@klass.blah.y.
|
762
|
+
expect(@klass.blah.x).to eq 10
|
763
|
+
expect(@klass.blah.y).to eq 20
|
764
764
|
end
|
765
765
|
|
766
766
|
it "setting the context values in a yielded block overrides the default values" do
|
@@ -768,8 +768,8 @@ describe Mixlib::Config do
|
|
768
768
|
b.x = 10
|
769
769
|
b.y = 20
|
770
770
|
end
|
771
|
-
@klass.blah.x.
|
772
|
-
@klass.blah.y.
|
771
|
+
expect(@klass.blah.x).to eq 10
|
772
|
+
expect(@klass.blah.y).to eq 20
|
773
773
|
end
|
774
774
|
|
775
775
|
it "after reset of the parent class, children are reset" do
|
@@ -1186,7 +1186,7 @@ alpha: beta
|
|
1186
1186
|
EOH
|
1187
1187
|
end
|
1188
1188
|
|
1189
|
-
it "turns
|
1189
|
+
it "turns JSON into method-style setting" do
|
1190
1190
|
allow(File).to receive(:exists?).and_return(true)
|
1191
1191
|
allow(File).to receive(:readable?).and_return(true)
|
1192
1192
|
allow(IO).to receive(:read).with("config.json").and_return(json)
|
@@ -1200,6 +1200,28 @@ alpha: beta
|
|
1200
1200
|
end
|
1201
1201
|
end
|
1202
1202
|
|
1203
|
+
describe ".from_toml" do
|
1204
|
+
let(:toml) do
|
1205
|
+
<<-EOH
|
1206
|
+
foo = ["bar", "baz", "matazz"]
|
1207
|
+
alpha = "beta"
|
1208
|
+
EOH
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
it "turns TOML into method-style setting" do
|
1212
|
+
allow(File).to receive(:exists?).and_return(true)
|
1213
|
+
allow(File).to receive(:readable?).and_return(true)
|
1214
|
+
allow(IO).to receive(:read).with("config.toml").and_return(toml)
|
1215
|
+
|
1216
|
+
expect(lambda do
|
1217
|
+
ConfigIt.from_file("config.toml")
|
1218
|
+
end).to_not raise_error
|
1219
|
+
|
1220
|
+
expect(ConfigIt.foo).to eql(%w{ bar baz matazz })
|
1221
|
+
expect(ConfigIt.alpha).to eql("beta")
|
1222
|
+
end
|
1223
|
+
end
|
1224
|
+
|
1203
1225
|
describe ".from_hash" do
|
1204
1226
|
let(:hash) do
|
1205
1227
|
{
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixlib-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tomlrb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|