config_volumizer 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/Gemfile +5 -1
- data/README.md +61 -15
- data/Rakefile +5 -0
- data/lib/config_volumizer/generator.rb +40 -4
- data/lib/config_volumizer/parser.rb +49 -44
- data/lib/config_volumizer/version.rb +1 -1
- data/lib/config_volumizer.rb +2 -2
- data/spec/config_volumizer_spec.rb +166 -63
- data/spec/generator_spec.rb +14 -5
- data/spec/spec_helper.rb +6 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc9530cd3c91c5a4fe838039cb30de8a14830e4f
|
4
|
+
data.tar.gz: 55016643bfc942b257bb0697bc033dde16befae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea31fbd58d7f9067f0de317969777793669c210b50f41b45d08cfa32d6eccb9c2e98368f9964a0441f496ccb66c950b3fb9c2c2dcd131e548ef594421b85ed3
|
7
|
+
data.tar.gz: ba803bd708d6c13b5bc2426269f40a880a28aef3da8c1dbd7865eb766d1f235990bc12d110b7b1bd3707bf58e039c3e973c729aba17cd63cc14258938a67ab10
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: Ra3YeFoOEOvZbWACZz5hRTUbqRq4Uewi9
|
data/Gemfile
CHANGED
@@ -2,13 +2,17 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
group :development do
|
5
|
+
group :development, :test do
|
6
|
+
gem 'awesome_print'
|
6
7
|
gem 'kramdown'
|
7
8
|
gem 'bundler'
|
8
9
|
gem 'rake'
|
9
10
|
gem 'rspec'
|
10
11
|
gem 'rubygems-tasks'
|
12
|
+
gem 'github_changelog_generator'
|
11
13
|
gem 'yard'
|
12
14
|
gem 'flay'
|
13
15
|
gem 'flog'
|
16
|
+
|
17
|
+
gem 'coveralls', require: false
|
14
18
|
end
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/payrollhero/config_volumizer.svg)](https://travis-ci.org/payrollhero/config_volumizer)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/payrollhero/config_volumizer/badges/gpa.svg)](https://codeclimate.com/github/payrollhero/config_volumizer)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/payrollhero/config_volumizer/badge.svg?branch=master)](https://coveralls.io/r/payrollhero/config_volumizer?branch=master)
|
6
|
+
[![Dependency Status](https://gemnasium.com/payrollhero/config_volumizer.svg)](https://gemnasium.com/payrollhero/config_volumizer)
|
5
7
|
|
6
8
|
* [Homepage](https://rubygems.org/gems/config_volumizer)
|
7
9
|
* [Documentation](http://rubydoc.info/gems/config_volumizer/frames)
|
@@ -32,31 +34,40 @@ some:
|
|
32
34
|
info a series of ENV variables like so:
|
33
35
|
|
34
36
|
```
|
35
|
-
|
36
|
-
|
37
|
-
some.setting[2] = three
|
38
|
-
some.with.another = setting
|
37
|
+
some_setting = one,two,three
|
38
|
+
some_with_another = setting
|
39
39
|
```
|
40
40
|
|
41
41
|
... and then just give it some volume with the volumizer to turn it back to the original rich structure
|
42
42
|
|
43
43
|
```ruby
|
44
|
-
|
44
|
+
mapping = { "some" => { "setting" => :value, "with" => { "another" => :value } } }
|
45
|
+
ConfigVolumizer.parse(ENV, 'some', mapping)
|
45
46
|
```
|
46
47
|
|
47
48
|
## Features
|
48
49
|
|
49
50
|
### Parsing
|
50
51
|
|
51
|
-
You can parse a flattened config via `ConfigVolumizer.parse(ENV, 'some')`
|
52
|
+
You can parse a flattened config via `ConfigVolumizer.parse(ENV, 'some', mapping)`
|
52
53
|
|
53
54
|
For example if your ENV was:
|
54
55
|
|
55
56
|
```
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
some_setting = one,two,three
|
58
|
+
some_with_another = setting
|
59
|
+
```
|
60
|
+
|
61
|
+
And you created a map like so:
|
62
|
+
```ruby
|
63
|
+
mapping = {
|
64
|
+
"some" => {
|
65
|
+
"setting" => :value,
|
66
|
+
"with" => {
|
67
|
+
"another" => :value
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
60
71
|
```
|
61
72
|
|
62
73
|
This would yield a {Hash} like the following:
|
@@ -87,13 +98,48 @@ some:
|
|
87
98
|
another: setting
|
88
99
|
```
|
89
100
|
|
90
|
-
You would get back
|
101
|
+
You would get back the data and mapping looking like this:
|
102
|
+
|
103
|
+
```yaml
|
104
|
+
some:
|
105
|
+
setting: :value
|
106
|
+
with:
|
107
|
+
another: :value
|
108
|
+
```
|
91
109
|
|
92
110
|
```yaml
|
93
|
-
"
|
94
|
-
"
|
95
|
-
|
96
|
-
|
111
|
+
"some_setting": one,two,three
|
112
|
+
"some_with_another": setting
|
113
|
+
```
|
114
|
+
|
115
|
+
## Deployment
|
116
|
+
|
117
|
+
In order to deploy a new version of the gem into the wild ...
|
118
|
+
|
119
|
+
You will need to configure your github api token for the changelog.
|
120
|
+
|
121
|
+
Generate a new token for changelogs [here](https://github.com/settings/tokens/new).
|
122
|
+
|
123
|
+
add:
|
124
|
+
|
125
|
+
```bash
|
126
|
+
export CHANGELOG_GITHUB_TOKEN=YOUR_CHANGELOG_API_TOKEN
|
127
|
+
```
|
128
|
+
|
129
|
+
somewhere in your shell init. (ie .zshrc or simillar)
|
130
|
+
|
131
|
+
|
132
|
+
```bash
|
133
|
+
vim lib/config_volumizer/version.rb
|
134
|
+
# set the new version
|
135
|
+
# commit the changed version file
|
136
|
+
# name your commit with the version number eg: "1.8.0"
|
137
|
+
rake release
|
138
|
+
# to push the gem to rubygems.org
|
139
|
+
rake changelog
|
140
|
+
# commit the changed changelog
|
141
|
+
# name your commit with the version again eg: "changelog for 1.8.0"
|
142
|
+
git push
|
97
143
|
```
|
98
144
|
|
99
145
|
## Install
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'ostruct'
|
1
2
|
module ConfigVolumizer
|
2
3
|
|
3
4
|
# Converts a {Hash} into a flattened {Hash} as a template for volumizing your configs
|
@@ -11,21 +12,56 @@ module ConfigVolumizer
|
|
11
12
|
# @param [Hash] data
|
12
13
|
# @return [Hash]
|
13
14
|
def generate(data)
|
15
|
+
OpenStruct.new(
|
16
|
+
env_hash: generate_env(data),
|
17
|
+
mapping_hash: generate_mapping(data),
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def generate_env(data)
|
24
|
+
data.inject({}) do |result, (key, value)|
|
25
|
+
process_env_item(result, key, value)
|
26
|
+
result
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_mapping(data)
|
14
31
|
data.inject({}) do |result, (key, value)|
|
15
|
-
|
32
|
+
result[key] = process_mapping_item(value)
|
33
|
+
result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_mapping_item(value)
|
38
|
+
case value
|
39
|
+
when Array
|
40
|
+
result = []
|
41
|
+
value.each_with_index do |item, index|
|
42
|
+
result[index] = process_mapping_item(item)
|
43
|
+
end
|
44
|
+
result.uniq
|
45
|
+
when Hash
|
46
|
+
result = {}
|
47
|
+
value.each do |key, item|
|
48
|
+
result[key] = process_mapping_item(item)
|
49
|
+
end
|
16
50
|
result
|
51
|
+
else
|
52
|
+
:value
|
17
53
|
end
|
18
54
|
end
|
19
55
|
|
20
|
-
def
|
56
|
+
def process_env_item(result, prefix, value)
|
21
57
|
case value
|
22
58
|
when Array
|
23
59
|
value.each_with_index do |item, index|
|
24
|
-
|
60
|
+
process_env_item(result, "#{prefix}_#{index}", item)
|
25
61
|
end
|
26
62
|
when Hash
|
27
63
|
value.each do |key, item|
|
28
|
-
|
64
|
+
process_env_item(result, "#{prefix}_#{key}", item)
|
29
65
|
end
|
30
66
|
else
|
31
67
|
result[prefix] = value
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'strscan'
|
2
2
|
require 'yaml'
|
3
|
+
require 'csv'
|
3
4
|
|
4
5
|
module ConfigVolumizer
|
5
6
|
module Parser
|
@@ -13,13 +14,15 @@ module ConfigVolumizer
|
|
13
14
|
#
|
14
15
|
# @param [Hash] source
|
15
16
|
# @param [String] base_name
|
17
|
+
# @param [Hash] mapping
|
16
18
|
# @return [Hash]
|
17
|
-
def parse(source,
|
19
|
+
def parse(source, mapping)
|
18
20
|
result = {}
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
mapping.each do |mapping_key, mapping_info|
|
22
|
+
source.each do |key, value|
|
23
|
+
if matches_name(mapping_key, key)
|
24
|
+
handle_item(result, key, value, mapping_key, mapping_info)
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
result
|
@@ -28,61 +31,63 @@ module ConfigVolumizer
|
|
28
31
|
private
|
29
32
|
|
30
33
|
def matches_name(base_name, key)
|
31
|
-
key == base_name || key =~ /^#{base_name}
|
34
|
+
key == base_name || key =~ /^#{base_name}_/
|
32
35
|
end
|
33
36
|
|
34
37
|
def format_value(value)
|
35
38
|
YAML.load(value)
|
36
39
|
end
|
37
40
|
|
38
|
-
def
|
39
|
-
|
40
|
-
result[key] ||= []
|
41
|
+
def format_array_value(value)
|
42
|
+
CSV.parse_line(value).map { |inner_value| format_value(inner_value) }
|
41
43
|
end
|
42
44
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
until scanner.eos?
|
59
|
-
dst, key = case next_fragment(scanner)
|
60
|
-
when /^\.(.+)/
|
61
|
-
handle_hash($~, dst, key)
|
62
|
-
when /\[(\d+)\]/
|
63
|
-
handle_array($~, dst, key)
|
64
|
-
end
|
45
|
+
def handle_item(result, name, value, mapping_key, mapping_info)
|
46
|
+
case mapping_info
|
47
|
+
when Array
|
48
|
+
handle_array_item(mapping_info, mapping_key, name, result, value)
|
49
|
+
when Hash
|
50
|
+
handle_hash_item(mapping_info, mapping_key, name, result, value)
|
51
|
+
when :value
|
52
|
+
result[mapping_key] = format_value(value)
|
53
|
+
when :hash
|
54
|
+
new_name = name.gsub(/^#{mapping_key}_/, '')
|
55
|
+
result[mapping_key] ||= {}
|
56
|
+
result[mapping_key][new_name] = format_value(value)
|
57
|
+
else
|
58
|
+
raise ArgumentError, "don't know how to deal with #{mapping_info.inspect}"
|
65
59
|
end
|
66
60
|
|
67
|
-
dst[key] = format_value(value)
|
68
61
|
end
|
69
62
|
|
70
|
-
def
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
def handle_hash_item(mapping_info, mapping_key, name, result, value)
|
64
|
+
result[mapping_key] ||= {}
|
65
|
+
new_name = name.gsub(/^#{mapping_key}_/, '')
|
66
|
+
mapping_info.each do |inner_mapping_key, inner_mapping_info|
|
67
|
+
if matches_name(inner_mapping_key, new_name)
|
68
|
+
handle_item(result[mapping_key], new_name, value, inner_mapping_key, inner_mapping_info)
|
69
|
+
end
|
70
|
+
end
|
74
71
|
end
|
75
72
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
73
|
+
def handle_array_item(mapping_info, mapping_key, name, result, value)
|
74
|
+
result[mapping_key] ||= []
|
75
|
+
mapping_info.each do |inner_mapping_info|
|
76
|
+
case inner_mapping_info
|
77
|
+
when :value
|
78
|
+
result[mapping_key] += format_array_value(value)
|
79
|
+
when :hash, Hash
|
80
|
+
handle_array_hash_item(inner_mapping_info, mapping_key, name, result, value)
|
81
|
+
else
|
82
|
+
raise "don't know how to handle: #{inner_mapping_info.inspect}"
|
83
|
+
end
|
84
|
+
end
|
80
85
|
end
|
81
86
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
def handle_array_hash_item(inner_mapping_info, mapping_key, name, result, value)
|
88
|
+
new_name = name.gsub(/^#{mapping_key}_(\d+)(?:_)?/, '')
|
89
|
+
index = $~[1].to_i
|
90
|
+
handle_item(result[mapping_key], new_name, value, index, inner_mapping_info)
|
86
91
|
end
|
87
92
|
|
88
93
|
end
|
data/lib/config_volumizer.rb
CHANGED
@@ -13,8 +13,8 @@ module ConfigVolumizer
|
|
13
13
|
# @param [Hash] source
|
14
14
|
# @param [String] base_name
|
15
15
|
# @return [Hash]
|
16
|
-
def parse(source,
|
17
|
-
Parser.parse(source,
|
16
|
+
def parse(source, mapping)
|
17
|
+
Parser.parse(source, mapping)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Generates a flattened config out of a data hash
|
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ConfigVolumizer do
|
4
4
|
describe '.parse' do
|
5
|
-
let(:
|
6
|
-
let(:result) { described_class.parse(input, key) }
|
5
|
+
let(:result) { described_class.parse(input, mapping) }
|
7
6
|
|
8
7
|
describe "1 level hash" do
|
9
8
|
let(:input) { { "ex" => "1a" } }
|
9
|
+
let(:mapping) { { "ex" => :value }}
|
10
10
|
let(:expected_result) { { 'ex' => '1a' } }
|
11
11
|
|
12
12
|
example do
|
@@ -15,11 +15,18 @@ describe ConfigVolumizer do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "2 level hash" do
|
18
|
-
let(:
|
18
|
+
let(:mapping) {
|
19
|
+
{
|
20
|
+
"ex1" => {
|
21
|
+
"bar" => :value,
|
22
|
+
"bar2" => :value,
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
19
26
|
let(:input) do
|
20
27
|
{
|
21
|
-
"
|
22
|
-
"
|
28
|
+
"ex1_bar" => "1a",
|
29
|
+
"ex1_bar2" => "2a",
|
23
30
|
}
|
24
31
|
end
|
25
32
|
let(:expected_result) do
|
@@ -37,12 +44,24 @@ describe ConfigVolumizer do
|
|
37
44
|
end
|
38
45
|
|
39
46
|
describe "3 level hash" do
|
40
|
-
let(:
|
47
|
+
let(:mapping) do
|
48
|
+
{
|
49
|
+
"ex3" => {
|
50
|
+
"one" => {
|
51
|
+
"two" => :value,
|
52
|
+
"three" => :value,
|
53
|
+
},
|
54
|
+
"two" => {
|
55
|
+
"three" => :value,
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
41
60
|
let(:input) do
|
42
61
|
{
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
62
|
+
"ex3_one_two" => "1a",
|
63
|
+
"ex3_one_three" => "2a",
|
64
|
+
"ex3_two_three" => "3a",
|
46
65
|
}
|
47
66
|
end
|
48
67
|
let(:expected_result) do
|
@@ -65,10 +84,16 @@ describe ConfigVolumizer do
|
|
65
84
|
end
|
66
85
|
|
67
86
|
describe "array of values in hash" do
|
87
|
+
let(:mapping) do
|
88
|
+
{
|
89
|
+
"ex" => {
|
90
|
+
"one" => [:value]
|
91
|
+
}
|
92
|
+
}
|
93
|
+
end
|
68
94
|
let(:input) do
|
69
95
|
{
|
70
|
-
"
|
71
|
-
"ex.one[1]" => "2a",
|
96
|
+
"ex_one" => "1a,2a",
|
72
97
|
}
|
73
98
|
end
|
74
99
|
let(:expected_result) do
|
@@ -83,10 +108,14 @@ describe ConfigVolumizer do
|
|
83
108
|
end
|
84
109
|
|
85
110
|
describe "just array of values" do
|
111
|
+
let(:mapping) do
|
112
|
+
{
|
113
|
+
"ex" => [:value],
|
114
|
+
}
|
115
|
+
end
|
86
116
|
let(:input) do
|
87
117
|
{
|
88
|
-
"ex
|
89
|
-
"ex[1]" => "2a",
|
118
|
+
"ex" => "1a,2a",
|
90
119
|
}
|
91
120
|
end
|
92
121
|
let(:expected_result) do
|
@@ -101,11 +130,19 @@ describe ConfigVolumizer do
|
|
101
130
|
end
|
102
131
|
|
103
132
|
describe "array of hashes" do
|
133
|
+
let(:mapping) do
|
134
|
+
{
|
135
|
+
"ex" => [{
|
136
|
+
"foo" => :value,
|
137
|
+
"bar" => :value,
|
138
|
+
}],
|
139
|
+
}
|
140
|
+
end
|
104
141
|
let(:input) do
|
105
142
|
{
|
106
|
-
"
|
107
|
-
"
|
108
|
-
"
|
143
|
+
"ex_0_foo" => "1a",
|
144
|
+
"ex_0_bar" => "2a",
|
145
|
+
"ex_1_foo" => "3a",
|
109
146
|
}
|
110
147
|
end
|
111
148
|
let(:expected_result) do
|
@@ -123,12 +160,23 @@ describe ConfigVolumizer do
|
|
123
160
|
end
|
124
161
|
|
125
162
|
describe "array of hash in hash" do
|
126
|
-
let(:
|
163
|
+
let(:mapping) do
|
164
|
+
{
|
165
|
+
"ex2" => {
|
166
|
+
"one" => [
|
167
|
+
{
|
168
|
+
"foo" => :value,
|
169
|
+
"bar" => :value,
|
170
|
+
}
|
171
|
+
]
|
172
|
+
},
|
173
|
+
}
|
174
|
+
end
|
127
175
|
let(:input) do
|
128
176
|
{
|
129
|
-
"
|
130
|
-
"
|
131
|
-
"
|
177
|
+
"ex2_one_0_foo" => "1a",
|
178
|
+
"ex2_one_0_bar" => "2a",
|
179
|
+
"ex2_one_1_foo" => "3a",
|
132
180
|
}
|
133
181
|
end
|
134
182
|
let(:expected_result) do
|
@@ -153,6 +201,11 @@ describe ConfigVolumizer do
|
|
153
201
|
end
|
154
202
|
|
155
203
|
describe "empty hash value" do
|
204
|
+
let(:mapping) {
|
205
|
+
{
|
206
|
+
"ex" => {}
|
207
|
+
}
|
208
|
+
}
|
156
209
|
let(:input) { { "ex" => "{}", } }
|
157
210
|
let(:expected_result) { { 'ex' => {} } }
|
158
211
|
|
@@ -162,6 +215,11 @@ describe ConfigVolumizer do
|
|
162
215
|
end
|
163
216
|
|
164
217
|
describe "empty array value" do
|
218
|
+
let(:mapping) {
|
219
|
+
{
|
220
|
+
"ex" => []
|
221
|
+
}
|
222
|
+
}
|
165
223
|
let(:input) { { "ex" => "[]", } }
|
166
224
|
let(:expected_result) { { 'ex' => [] } }
|
167
225
|
|
@@ -170,56 +228,101 @@ describe ConfigVolumizer do
|
|
170
228
|
end
|
171
229
|
end
|
172
230
|
|
173
|
-
describe "
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
231
|
+
describe "hash values" do
|
232
|
+
context "at root" do
|
233
|
+
let(:mapping) do
|
234
|
+
{
|
235
|
+
"ex" => :hash
|
236
|
+
}
|
237
|
+
end
|
238
|
+
let(:input) do
|
239
|
+
{
|
240
|
+
'ex_one' => "1a",
|
241
|
+
'ex_two' => "2a",
|
242
|
+
'ex_three' => "3a",
|
243
|
+
}
|
244
|
+
end
|
245
|
+
let(:expected_result) do
|
246
|
+
{
|
247
|
+
'ex' => {
|
248
|
+
"one" => "1a",
|
249
|
+
"two" => "2a",
|
250
|
+
"three" => "3a",
|
251
|
+
}
|
252
|
+
}
|
253
|
+
end
|
190
254
|
|
191
|
-
|
192
|
-
|
255
|
+
example do
|
256
|
+
expect(result).to eq(expected_result)
|
257
|
+
end
|
193
258
|
end
|
194
|
-
end
|
195
259
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
260
|
+
context "in a hash" do
|
261
|
+
let(:mapping) do
|
262
|
+
{
|
263
|
+
"ex" => {
|
264
|
+
"ex2" => :hash
|
265
|
+
}
|
266
|
+
}
|
267
|
+
end
|
268
|
+
let(:input) do
|
269
|
+
{
|
270
|
+
'ex_ex2_one' => "1a",
|
271
|
+
'ex_ex2_two' => "2a",
|
272
|
+
'ex_ex2_three' => "3a",
|
273
|
+
}
|
274
|
+
end
|
275
|
+
let(:expected_result) do
|
276
|
+
{
|
277
|
+
'ex' => {
|
278
|
+
'ex2' => {
|
279
|
+
"one" => "1a",
|
280
|
+
"two" => "2a",
|
281
|
+
"three" => "3a",
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
end
|
286
|
+
|
287
|
+
example do
|
288
|
+
expect(result).to eq(expected_result)
|
289
|
+
end
|
204
290
|
end
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
291
|
+
|
292
|
+
context "in an array" do
|
293
|
+
let(:mapping) do
|
294
|
+
{
|
295
|
+
"ex" => [:hash]
|
296
|
+
}
|
297
|
+
end
|
298
|
+
let(:input) do
|
299
|
+
{
|
300
|
+
'ex_0_one' => "1a",
|
301
|
+
'ex_0_two' => "2a",
|
302
|
+
'ex_0_three' => "3a",
|
303
|
+
'ex_1_two' => "4a",
|
304
|
+
}
|
305
|
+
end
|
306
|
+
let(:expected_result) do
|
307
|
+
{
|
308
|
+
'ex' => [
|
309
|
+
{
|
310
|
+
"one" => "1a",
|
311
|
+
"two" => "2a",
|
312
|
+
"three" => "3a",
|
313
|
+
},
|
314
|
+
{
|
315
|
+
"two" => "4a",
|
316
|
+
}
|
215
317
|
]
|
216
|
-
|
217
|
-
|
218
|
-
end
|
318
|
+
}
|
319
|
+
end
|
219
320
|
|
220
|
-
|
221
|
-
|
321
|
+
example do
|
322
|
+
expect(result).to eq(expected_result)
|
323
|
+
end
|
222
324
|
end
|
223
325
|
end
|
326
|
+
|
224
327
|
end
|
225
328
|
end
|
data/spec/generator_spec.rb
CHANGED
@@ -13,13 +13,22 @@ describe ConfigVolumizer do
|
|
13
13
|
]
|
14
14
|
}
|
15
15
|
}
|
16
|
-
|
16
|
+
expected_env_data = {
|
17
17
|
"one" => "two",
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
18
|
+
"three_four" => "five",
|
19
|
+
"three_six_0" => "seven",
|
20
|
+
"three_six_1" => "eight",
|
21
21
|
}
|
22
|
-
|
22
|
+
expected_mapping_data = {
|
23
|
+
"one" => :value,
|
24
|
+
"three" => {
|
25
|
+
"four" => :value,
|
26
|
+
"six" => [:value]
|
27
|
+
}
|
28
|
+
}
|
29
|
+
result = described_class.generate(data)
|
30
|
+
expect(result.env_hash).to eq(expected_env_data)
|
31
|
+
expect(result.mapping_hash).to eq(expected_mapping_data)
|
23
32
|
end
|
24
33
|
end
|
25
34
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_volumizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Banasik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Allows turning dot notation config from ENV to rich Hash/Array structures
|
14
14
|
email: piotr.banasik@gmail.com
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- ".coveralls.yml"
|
19
20
|
- ".document"
|
20
21
|
- ".gitignore"
|
21
22
|
- ".rspec"
|