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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c9d095029273d13356b6ca01b179ebb1a96e0a3
4
- data.tar.gz: e3a485583a06cda2ed86bef8fb293cd239c96623
3
+ metadata.gz: 42c45c99e0917eaee3c502509dccaaab2c44a140
4
+ data.tar.gz: 75275ed680eea2d2b0b1a07448803add3c0fedbd
5
5
  SHA512:
6
- metadata.gz: e1b3d7b5dd354e1a01794275c786054182018b158d07a1fb942bdc23dd9bba1e23fb8feb74193e36d598f618530bcaec17a9ef23413813ae07e72d5b6da85148
7
- data.tar.gz: b7e76f0b580e107aada88783fcc844c4dfb3ce30625a6dae2803702a67b081bf595b59a92ddab475c179c1180aed03e21540f74fb447e1f7525d24c2faaceac9
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.map { |v| expand(v) }
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(", ")
@@ -1,3 +1,3 @@
1
1
  module ConfigHound
2
- VERSION = "1.3.2"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -113,37 +113,56 @@ describe ConfigHound::Interpolation do
113
113
 
114
114
  end
115
115
 
116
- end
116
+ context "with circular reference" do
117
117
 
118
- context "with circular reference" do
118
+ let(:input) do
119
+ {
120
+ "ping" => "refers to <(pong)>",
121
+ "pong" => "refers to <(ping)>"
122
+ }
123
+ end
119
124
 
120
- let(:input) do
121
- {
122
- "ping" => "refers to <(pong)>",
123
- "pong" => "refers to <(ping)>"
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
- end
133
+ context "with unresolved reference" do
134
134
 
135
- context "with unresolved reference" do
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
- it "raises a ReferenceError" do
144
- expect {
145
- described_class.expand(input)
146
- }.to raise_error(ConfigHound::Interpolation::ReferenceError)
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.3.2
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-07-25 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dig_rb