config_volumizer 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +19 -0
- data/README.md +47 -2
- data/Rakefile +1 -1
- data/lib/config_volumizer.rb +16 -1
- data/lib/config_volumizer/parser.rb +0 -1
- data/lib/config_volumizer/version.rb +1 -1
- data/spec/config_volumizer_spec.rb +100 -1
- metadata +4 -4
- data/ChangeLog.md +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0c29f0402462a29c95d7e2712a62d557ddfb71d
|
4
|
+
data.tar.gz: 52d81de5d4a22e8ed0aa6e7c96eae005f8484730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92db0ba571ec57b8b35116e8258808f230b5063b9bc0369011f99e15677cdbbfb5441ad98d6853f51cb178572ba7afc45e76125ba17d0af70c6be34e98cd883d
|
7
|
+
data.tar.gz: d2942c52b731795b2034d3730a8ddc67338741d4553657580166f89d21c29a254bf6543eec69671cb49e33337d46e15cbc311bcbcf9bf5437be97d17baa5ab3d
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [v0.3.0](https://github.com/payrollhero/config_volumizer/tree/v0.3.0) (2015-04-18)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/payrollhero/config_volumizer/compare/v0.2.0...v0.3.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- effectively a rewrite that uses mapping hashes to describe the syntax [\#1](https://github.com/payrollhero/config_volumizer/pull/1) ([piotrb](https://github.com/piotrb))
|
10
|
+
|
11
|
+
## [v0.2.0](https://github.com/payrollhero/config_volumizer/tree/v0.2.0) (2015-04-03)
|
12
|
+
|
13
|
+
[Full Changelog](https://github.com/payrollhero/config_volumizer/compare/v0.1.0...v0.2.0)
|
14
|
+
|
15
|
+
## [v0.1.0](https://github.com/payrollhero/config_volumizer/tree/v0.1.0) (2015-04-03)
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -42,14 +42,14 @@ some_with_another = setting
|
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
mapping = { "some" => { "setting" => :value, "with" => { "another" => :value } } }
|
45
|
-
ConfigVolumizer.parse(ENV,
|
45
|
+
ConfigVolumizer.parse(ENV, mapping)
|
46
46
|
```
|
47
47
|
|
48
48
|
## Features
|
49
49
|
|
50
50
|
### Parsing
|
51
51
|
|
52
|
-
You can parse a flattened config via `ConfigVolumizer.parse(ENV,
|
52
|
+
You can parse a flattened config via `ConfigVolumizer.parse(ENV, mapping)`
|
53
53
|
|
54
54
|
For example if your ENV was:
|
55
55
|
|
@@ -82,6 +82,51 @@ some:
|
|
82
82
|
another: setting
|
83
83
|
```
|
84
84
|
|
85
|
+
### Fetching values (shorthand for parse)
|
86
|
+
|
87
|
+
You can fetch a specific key from the given source
|
88
|
+
|
89
|
+
For example:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
env = {
|
93
|
+
"some_setting" => "one,two,three",
|
94
|
+
"some_with_another" => "setting",
|
95
|
+
}
|
96
|
+
|
97
|
+
mapping = {
|
98
|
+
"setting" => [:value],
|
99
|
+
"with" => {
|
100
|
+
"another" => :value
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
ConfigVolumizer.fetch(env, "some", mapping)
|
105
|
+
|
106
|
+
# returns:
|
107
|
+
{
|
108
|
+
"setting" => [
|
109
|
+
"one","two","three"
|
110
|
+
],
|
111
|
+
"with" => {
|
112
|
+
"another" => "setting",
|
113
|
+
}
|
114
|
+
}
|
115
|
+
```
|
116
|
+
|
117
|
+
fetch works much like Hash#fetch, so you can pass an additional
|
118
|
+
parameter for the default value, as well as use a block default value.
|
119
|
+
|
120
|
+
eg:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
ConfigVolumizer.fetch(env, "another", mapping, "default_value")
|
124
|
+
# => "default_value"
|
125
|
+
|
126
|
+
ConfigVolumizer.fetch(env, "another", mapping) { |key| "default_#{key}" }
|
127
|
+
# => "default_another"
|
128
|
+
```
|
129
|
+
|
85
130
|
### Generation
|
86
131
|
|
87
132
|
You can generate a flat list of configs (mostly as examples for your actual config) via:
|
data/Rakefile
CHANGED
data/lib/config_volumizer.rb
CHANGED
@@ -11,12 +11,27 @@ module ConfigVolumizer
|
|
11
11
|
# @see ConfigVolumizer::Parser.parse
|
12
12
|
#
|
13
13
|
# @param [Hash] source
|
14
|
-
# @param [
|
14
|
+
# @param [Hash] mapping
|
15
15
|
# @return [Hash]
|
16
16
|
def parse(source, mapping)
|
17
17
|
Parser.parse(source, mapping)
|
18
18
|
end
|
19
19
|
|
20
|
+
# Fetches the data described by the mapping from the source
|
21
|
+
# works similar to #parse, but has a default value mechanism
|
22
|
+
# and skips the root key
|
23
|
+
#
|
24
|
+
# @param [Hash] source
|
25
|
+
# @param [String] mapping_key
|
26
|
+
# @param [Object] mapping_info
|
27
|
+
# @param [Object] default - default value if key not found
|
28
|
+
# @param [proc] block - default value proc (is passed key as parameter)
|
29
|
+
# @return [Object]
|
30
|
+
def fetch(source, mapping_key, mapping_info, default=nil, &block)
|
31
|
+
value = Parser.parse(source, mapping_key => mapping_info)
|
32
|
+
value.fetch(mapping_key, *[default].compact, &block)
|
33
|
+
end
|
34
|
+
|
20
35
|
# Generates a flattened config out of a data hash
|
21
36
|
#
|
22
37
|
# @see ConfigVolumizer::Generator.generate
|
@@ -6,7 +6,7 @@ describe ConfigVolumizer do
|
|
6
6
|
|
7
7
|
describe "1 level hash" do
|
8
8
|
let(:input) { { "ex" => "1a" } }
|
9
|
-
let(:mapping) { { "ex" => :value }}
|
9
|
+
let(:mapping) { { "ex" => :value } }
|
10
10
|
let(:expected_result) { { 'ex' => '1a' } }
|
11
11
|
|
12
12
|
example do
|
@@ -325,4 +325,103 @@ describe ConfigVolumizer do
|
|
325
325
|
end
|
326
326
|
|
327
327
|
end
|
328
|
+
|
329
|
+
describe "fetch" do
|
330
|
+
let(:key_name) { "some_gem_settings" }
|
331
|
+
let(:result) { ConfigVolumizer.fetch(env, key_name, mapping) }
|
332
|
+
|
333
|
+
context "basic example" do
|
334
|
+
let(:env) do
|
335
|
+
{
|
336
|
+
"some_gem_settings_one" => "hello",
|
337
|
+
"some_gem_settings_two" => "world",
|
338
|
+
"some_gem_settings_three" => "yay",
|
339
|
+
}
|
340
|
+
end
|
341
|
+
let(:mapping) { :hash }
|
342
|
+
let(:expected) do
|
343
|
+
{
|
344
|
+
"one" => "hello",
|
345
|
+
"two" => "world",
|
346
|
+
"three" => "yay",
|
347
|
+
}
|
348
|
+
end
|
349
|
+
|
350
|
+
example { expect(result).to eq(expected) }
|
351
|
+
end
|
352
|
+
|
353
|
+
context "complex example" do
|
354
|
+
let(:env) do
|
355
|
+
{
|
356
|
+
"some_gem_settings_key1_one" => "hello1",
|
357
|
+
"some_gem_settings_key1_two" => "hello2",
|
358
|
+
"some_gem_settings_key2" => "hello,world",
|
359
|
+
"some_gem_settings_key3_0_foo_one" => "1",
|
360
|
+
"some_gem_settings_key3_0_foo_two" => "2",
|
361
|
+
"some_gem_settings_key3_1_foo_one" => "3",
|
362
|
+
"some_gem_settings_key3_1_foo_two" => "4",
|
363
|
+
"some_gem_settings_key3_2_foo_one" => "5",
|
364
|
+
"some_gem_settings_key3_2_foo_two" => "6",
|
365
|
+
}
|
366
|
+
end
|
367
|
+
let(:mapping) do
|
368
|
+
{
|
369
|
+
"key1" => :hash,
|
370
|
+
"key2" => [:value],
|
371
|
+
"key3" => [
|
372
|
+
{
|
373
|
+
"foo" => :hash,
|
374
|
+
}
|
375
|
+
],
|
376
|
+
}
|
377
|
+
end
|
378
|
+
let(:expected) do
|
379
|
+
{
|
380
|
+
"key1" => { "one" => "hello1", "two" => "hello2" },
|
381
|
+
"key2" => ["hello", "world"],
|
382
|
+
"key3" => [{ "foo" => { "one" => 1, "two" => 2 } },
|
383
|
+
{ "foo" => { "one" => 3, "two" => 4 } },
|
384
|
+
{ "foo" => { "one" => 5, "two" => 6 } }]
|
385
|
+
}
|
386
|
+
end
|
387
|
+
|
388
|
+
example { expect(result).to eq(expected) }
|
389
|
+
end
|
390
|
+
|
391
|
+
context "key not found" do
|
392
|
+
let(:key_name) { "not_found" }
|
393
|
+
let(:env) do
|
394
|
+
{
|
395
|
+
"some_gem_settings_one" => "hello",
|
396
|
+
"some_gem_settings_two" => "world",
|
397
|
+
"some_gem_settings_three" => "yay",
|
398
|
+
}
|
399
|
+
end
|
400
|
+
let(:mapping) { :hash }
|
401
|
+
|
402
|
+
context "not specifying a default" do
|
403
|
+
let(:result) { ConfigVolumizer.fetch(env, key_name, mapping) }
|
404
|
+
|
405
|
+
example do
|
406
|
+
expect { result }.to raise_exception(KeyError)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
context "specifying a default value" do
|
411
|
+
let(:result) { ConfigVolumizer.fetch(env, key_name, mapping, "default_value") }
|
412
|
+
let(:expected) { "default_value" }
|
413
|
+
|
414
|
+
example { expect(result).to eq(expected) }
|
415
|
+
end
|
416
|
+
|
417
|
+
context "specifying a default block" do
|
418
|
+
let(:result) { ConfigVolumizer.fetch(env, key_name, mapping) { |key| "default_#{key}" } }
|
419
|
+
let(:expected) { "default_not_found" }
|
420
|
+
|
421
|
+
example { expect(result).to eq(expected) }
|
422
|
+
end
|
423
|
+
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
328
427
|
end
|
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.3.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2015-12-01 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
|
@@ -22,7 +22,7 @@ files:
|
|
22
22
|
- ".rspec"
|
23
23
|
- ".travis.yml"
|
24
24
|
- ".yardopts"
|
25
|
-
-
|
25
|
+
- CHANGELOG.md
|
26
26
|
- Gemfile
|
27
27
|
- LICENSE.txt
|
28
28
|
- README.md
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
57
|
rubyforge_project:
|
58
|
-
rubygems_version: 2.4.5
|
58
|
+
rubygems_version: 2.4.5.1
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: Adds volume to an otherwise flat config
|