config_hound 1.3.2 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/config_hound/interpolation.rb +12 -1
- data/lib/config_hound/version.rb +1 -1
- data/spec/config_hound/interpolation_spec.rb +41 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42c45c99e0917eaee3c502509dccaaab2c44a140
|
4
|
+
data.tar.gz: 75275ed680eea2d2b0b1a07448803add3c0fedbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afb38dc4ddf38cb00728a0c11cf4daee9123ce6792aca6c6bf9bec30061a95ac559d446c5f72ee86d147c2655c4cc2c4bbd1c2cd8f721dcf1602a490169b8b68
|
7
|
+
data.tar.gz: 7d010c6bf7379a446717b56943b8dcaa69fd2130339a398fa1a552409b169ee29238d455b47ffc0fbdbcda0d7cfa6d91e4e562b9f15bb5349e41423c28e539d4
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# ConfigHound
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/config_hound.png)](http://badge.fury.io/rb/config_hound)
|
3
4
|
[![Build Status](https://travis-ci.org/mdub/config_hound.svg?branch=master)](https://travis-ci.org/mdub/config_hound)
|
4
5
|
|
5
6
|
ConfigHound makes it easy to load configuration data.
|
@@ -30,7 +30,7 @@ module ConfigHound
|
|
30
30
|
when Hash
|
31
31
|
expand_hash(input)
|
32
32
|
when Array
|
33
|
-
input
|
33
|
+
expand_array(input)
|
34
34
|
when /\A<\(([\w.]+)\)>\Z/
|
35
35
|
evaluate_expression($1)
|
36
36
|
when /<\([\w.]+\)>/
|
@@ -50,6 +50,17 @@ module ConfigHound
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
def expand_array(input)
|
54
|
+
input.each_with_object([]) do |v, result|
|
55
|
+
case v
|
56
|
+
when /\A<\*\(([\w.]+)\)>\Z/
|
57
|
+
result.push(*evaluate_expression($1))
|
58
|
+
else
|
59
|
+
result.push(expand(v))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
53
64
|
def evaluate_expression(expr)
|
54
65
|
if seen.include?(expr)
|
55
66
|
details = seen.map { |e| "<(#{e})>" }.join(", ")
|
data/lib/config_hound/version.rb
CHANGED
@@ -113,37 +113,56 @@ describe ConfigHound::Interpolation do
|
|
113
113
|
|
114
114
|
end
|
115
115
|
|
116
|
-
|
116
|
+
context "with circular reference" do
|
117
117
|
|
118
|
-
|
118
|
+
let(:input) do
|
119
|
+
{
|
120
|
+
"ping" => "refers to <(pong)>",
|
121
|
+
"pong" => "refers to <(ping)>"
|
122
|
+
}
|
123
|
+
end
|
119
124
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
125
|
+
it "raises a ReferenceError" do
|
126
|
+
expect {
|
127
|
+
output
|
128
|
+
}.to raise_error(ConfigHound::Interpolation::ReferenceError)
|
129
|
+
end
|
126
130
|
|
127
|
-
it "raises a ReferenceError" do
|
128
|
-
expect {
|
129
|
-
described_class.expand(input)
|
130
|
-
}.to raise_error(ConfigHound::Interpolation::ReferenceError)
|
131
131
|
end
|
132
132
|
|
133
|
-
|
133
|
+
context "with unresolved reference" do
|
134
134
|
|
135
|
-
|
135
|
+
let(:input) do
|
136
|
+
{
|
137
|
+
"foo" => "refers to <(bar)>"
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
it "raises a ReferenceError" do
|
142
|
+
expect {
|
143
|
+
output
|
144
|
+
}.to raise_error(ConfigHound::Interpolation::ReferenceError)
|
145
|
+
end
|
136
146
|
|
137
|
-
let(:input) do
|
138
|
-
{
|
139
|
-
"foo" => "refers to <(bar)>"
|
140
|
-
}
|
141
147
|
end
|
142
148
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
149
|
+
context "with a splat reference" do
|
150
|
+
|
151
|
+
let(:input) do
|
152
|
+
{
|
153
|
+
"x" => [2, 3],
|
154
|
+
"y" => [
|
155
|
+
"juan",
|
156
|
+
"<*(x)>",
|
157
|
+
"for",
|
158
|
+
]
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
it "expands the reference" do
|
163
|
+
expect(output["y"]).to eql(["juan", 2, 3, "for"])
|
164
|
+
end
|
165
|
+
|
147
166
|
end
|
148
167
|
|
149
168
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_hound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dig_rb
|