configulator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/configulator/config_template.rb +19 -0
- data/lib/configulator/version.rb +1 -1
- data/test/configulator_test.rb +12 -0
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 042b0b6eebf14f2b5c128f966b55830fcbd4a2ea
|
4
|
+
data.tar.gz: 334300f15b8092b89488c51b4a40c67a6a3b756f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b000b33b61b7be27fb5b7e9d406c445f1d5a23db2e2217413c6f7dfab8fbed176f5495189557a0cfb44278baecebc8e0ea13de0ab69b4b1ade252780562045fb
|
7
|
+
data.tar.gz: 85d5be9be13bb433eb916fe21a51cc2621b81d779626eefdfc9b940655a02e2fffa375f9dc2792c030dca2df6b7eb55c1ab80d0e98143e5a41460cd6d921f936
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# Configulator : Generate Config Files
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/bmuller/configulator.svg)](https://travis-ci.org/bmuller/configulator)
|
2
4
|
|
3
5
|
Configurator allows you to maintain a single file with configuration values that can be used to generate other config files based on templates.
|
4
6
|
|
@@ -35,7 +35,26 @@ module Configulator
|
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
38
|
+
def collapse(json, prefix=nil)
|
39
|
+
prefix ||= []
|
40
|
+
results = []
|
41
|
+
json.each do |key, value|
|
42
|
+
keys = prefix + [key]
|
43
|
+
if value.is_a?(Hash)
|
44
|
+
results += collapse(value, keys)
|
45
|
+
else
|
46
|
+
results << [keys.join('_'), value]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
results
|
50
|
+
end
|
51
|
+
|
38
52
|
def make_binding(env)
|
53
|
+
# first, collapse if there is a heirarchy
|
54
|
+
env = collapse(env).each_with_object({}) do |kv,h|
|
55
|
+
h[kv.first] = kv.last
|
56
|
+
end
|
57
|
+
|
39
58
|
klass = ConfStruct.new *env.keys.map(&:intern)
|
40
59
|
k = klass.new *env.values
|
41
60
|
# support up to 5 levels of embedding
|
data/lib/configulator/version.rb
CHANGED
data/test/configulator_test.rb
CHANGED
@@ -17,6 +17,18 @@ class ConfigulatorTest < Test::Unit::TestCase
|
|
17
17
|
assert_equal c.three, "something one two"
|
18
18
|
end
|
19
19
|
|
20
|
+
def test_json_with_hierarchy
|
21
|
+
input = {
|
22
|
+
"one" => "something",
|
23
|
+
"two" => { "three" => "four" },
|
24
|
+
"five" => { "six" => { "seven" => [1, 2] } }
|
25
|
+
}
|
26
|
+
c = Configulator.from_json(JSON.dump(input))
|
27
|
+
assert_equal c.one, "something"
|
28
|
+
assert_equal c.two_three, "four"
|
29
|
+
assert_equal c.five_six_seven, [1, 2]
|
30
|
+
end
|
31
|
+
|
20
32
|
def test_json_load_with_env
|
21
33
|
input = {
|
22
34
|
"default" => {
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configulator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Muller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
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
54
|
version: '0'
|
55
55
|
description: Configurator allows you to maintain a single file with configuration
|
@@ -61,8 +61,8 @@ executables:
|
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
|
-
-
|
65
|
-
-
|
64
|
+
- .gitignore
|
65
|
+
- .travis.yml
|
66
66
|
- Gemfile
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
@@ -83,17 +83,17 @@ require_paths:
|
|
83
83
|
- lib
|
84
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - '>='
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.0.14
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Generate config files from a template
|