configurate 0.4.0 → 0.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 +5 -0
- data/README.md +2 -2
- data/lib/configurate/provider/toml.rb +9 -2
- data/spec/configurate/provider/toml_spec.rb +10 -8
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5917dff879c04bd7e35104f02ed093e0ade7628503b70eaa9ba9f988250ce89d
|
4
|
+
data.tar.gz: 0ac06ee31c43264bac9001e7dad1c4fa18e9116dd02adfd325f21281d65ac2a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf82b6d8a397b3473bf4abc11722a7fb43f98981ee25142786a37c7ba46c1d847324a43f6950ad8997b7fd6db1186d3cd0e7d9a554b28e4f3a5d07b742075bb
|
7
|
+
data.tar.gz: 28022b6871d3282a5c8283b701bc9a45b1e2519470cb4762e9cb0d4a1875c86c5d16648c8eead096bc0da0da4cc09d477b2c27ef398b9b8c55c0638a4c245b6c
|
data/Changelog.md
CHANGED
data/README.md
CHANGED
@@ -137,8 +137,8 @@ Config.stuff.param # => "foo"
|
|
137
137
|
Config.stuff.nested.param # => "bar"
|
138
138
|
```
|
139
139
|
|
140
|
-
This provider depends on the [tomlrb](https://github.com/fbernier/tomlrb) gem.
|
141
|
-
needs an explicit `require 'configurate/provider/toml' to be available.
|
140
|
+
This provider depends on the [toml-rb](https://github.com/emancu/toml-rb) or the [tomlrb](https://github.com/fbernier/tomlrb) gem.
|
141
|
+
This is why it is not loaded by default and needs an explicit `require 'configurate/provider/toml'` to be available. If both are available, toml-rb is preferred.
|
142
142
|
|
143
143
|
The initializer takes a path to the configuration file a the mandatory first argument and
|
144
144
|
the following optional parameters:
|
@@ -1,13 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "configurate"
|
4
|
-
require "tomlrb"
|
5
4
|
|
6
5
|
module Configurate
|
7
6
|
module Provider
|
8
7
|
# This provider tries to open a TOML file and does nested lookups
|
9
8
|
# in it.
|
10
9
|
class TOML < StringHash
|
10
|
+
begin
|
11
|
+
require "toml-rb"
|
12
|
+
PARSER = TomlRB
|
13
|
+
rescue LoadError => e
|
14
|
+
require "tomlrb"
|
15
|
+
PARSER = Tomlrb
|
16
|
+
end
|
17
|
+
|
11
18
|
# @param file [String] the path to the file
|
12
19
|
# @param namespace [String] optionally set this as the root
|
13
20
|
# @param required [Boolean] whether or not to raise an error if
|
@@ -17,7 +24,7 @@ module Configurate
|
|
17
24
|
# @raise [ArgumentError] if the namespace isn't found in the file
|
18
25
|
# @raise [Errno:ENOENT] if the file isn't found
|
19
26
|
def initialize file, namespace: nil, required: true, raise_on_missing: false
|
20
|
-
super(
|
27
|
+
super(PARSER.load_file(file),
|
21
28
|
namespace: namespace,
|
22
29
|
required: required,
|
23
30
|
raise_on_missing: raise_on_missing,
|
@@ -4,6 +4,8 @@ require "spec_helper"
|
|
4
4
|
require "configurate/provider/toml"
|
5
5
|
|
6
6
|
describe Configurate::Provider::TOML do
|
7
|
+
PARSER = Configurate::Provider::TOML::PARSER
|
8
|
+
|
7
9
|
let(:settings) {
|
8
10
|
{
|
9
11
|
"toplevel" => "bar",
|
@@ -16,12 +18,12 @@ describe Configurate::Provider::TOML do
|
|
16
18
|
describe "#initialize" do
|
17
19
|
it "loads the file" do
|
18
20
|
file = "foobar.toml"
|
19
|
-
expect(
|
21
|
+
expect(PARSER).to receive(:load_file).with(file).and_return({})
|
20
22
|
described_class.new file
|
21
23
|
end
|
22
24
|
|
23
25
|
it "raises if the file is not found" do
|
24
|
-
allow(
|
26
|
+
allow(PARSER).to receive(:load_file).and_raise(Errno::ENOENT)
|
25
27
|
expect {
|
26
28
|
silence_stderr do
|
27
29
|
described_class.new "foo"
|
@@ -32,13 +34,13 @@ describe Configurate::Provider::TOML do
|
|
32
34
|
context "with a namespace" do
|
33
35
|
it "looks in the file for that namespace" do
|
34
36
|
namespace = "some.nested"
|
35
|
-
allow(
|
37
|
+
allow(PARSER).to receive(:load_file).and_return(settings)
|
36
38
|
provider = described_class.new "bla", namespace: namespace
|
37
39
|
expect(provider.instance_variable_get(:@settings)).to eq settings["some"]["nested"]
|
38
40
|
end
|
39
41
|
|
40
42
|
it "raises if the namespace isn't found" do
|
41
|
-
allow(
|
43
|
+
allow(PARSER).to receive(:load_file).and_return({})
|
42
44
|
expect {
|
43
45
|
silence_stderr do
|
44
46
|
described_class.new "bla", namespace: "bar"
|
@@ -47,7 +49,7 @@ describe Configurate::Provider::TOML do
|
|
47
49
|
end
|
48
50
|
|
49
51
|
it "works with an empty namespace in the file" do
|
50
|
-
allow(
|
52
|
+
allow(PARSER).to receive(:load_file).and_return("foo" => {"bar" => nil})
|
51
53
|
expect {
|
52
54
|
silence_stderr do
|
53
55
|
described_class.new "bla", namespace: "foo.bar"
|
@@ -58,7 +60,7 @@ describe Configurate::Provider::TOML do
|
|
58
60
|
|
59
61
|
context "with required set to false" do
|
60
62
|
it "doesn't raise if a file isn't found" do
|
61
|
-
allow(
|
63
|
+
allow(PARSER).to receive(:load_file).and_raise(Errno::ENOENT)
|
62
64
|
expect {
|
63
65
|
silence_stderr do
|
64
66
|
described_class.new "not_me", required: false
|
@@ -67,7 +69,7 @@ describe Configurate::Provider::TOML do
|
|
67
69
|
end
|
68
70
|
|
69
71
|
it "doesn't raise if a namespace isn't found" do
|
70
|
-
allow(
|
72
|
+
allow(PARSER).to receive(:load_file).and_return({})
|
71
73
|
expect {
|
72
74
|
silence_stderr do
|
73
75
|
described_class.new "bla", namespace: "foo", required: false
|
@@ -79,7 +81,7 @@ describe Configurate::Provider::TOML do
|
|
79
81
|
|
80
82
|
describe "#lookup_path" do
|
81
83
|
before do
|
82
|
-
allow(
|
84
|
+
allow(PARSER).to receive(:load_file).and_return(settings)
|
83
85
|
@provider = described_class.new "dummy"
|
84
86
|
end
|
85
87
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonne Haß
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: toml-rb
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.0.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.0.1
|
55
55
|
description: Configurate is a flexible configuration system that can read settings
|
56
56
|
from multiple sources at the same time.
|
57
57
|
email: me@jhass.eu
|
@@ -87,7 +87,7 @@ homepage: http://jhass.github.io/configurate
|
|
87
87
|
licenses:
|
88
88
|
- MIT
|
89
89
|
metadata: {}
|
90
|
-
post_install_message:
|
90
|
+
post_install_message:
|
91
91
|
rdoc_options: []
|
92
92
|
require_paths:
|
93
93
|
- lib
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubygems_version: 3.1.2
|
106
|
-
signing_key:
|
106
|
+
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Flexbile configuration system
|
109
109
|
test_files:
|