hierarchical_config 0.2 → 0.3
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.
- data/README.markdown +11 -4
- data/lib/hierarchical_config.rb +29 -3
- metadata +40 -22
data/README.markdown
CHANGED
@@ -12,7 +12,9 @@ HierarchicalConfig is a library that implements a strategy for configuring an ap
|
|
12
12
|
without repeating yourself.
|
13
13
|
4. You should be able to change configuration per box based on deploy
|
14
14
|
that does not affect the defaults or requirements that are checked in
|
15
|
-
to source control.
|
15
|
+
to source control. This can be accomplished with a deploy time file
|
16
|
+
or environment variables that are also highly configurable and
|
17
|
+
validated.
|
16
18
|
|
17
19
|
## Usage
|
18
20
|
|
@@ -64,6 +66,11 @@ doesn't know about.
|
|
64
66
|
root:
|
65
67
|
child_b: 8
|
66
68
|
|
69
|
+
env_vars:
|
70
|
+
super_secret_password: SUPER_SECRET
|
71
|
+
env_vars[production]:
|
72
|
+
super_secret_password: SUPER_DUPER_SECRET
|
73
|
+
|
67
74
|
### config/app-overrides.yml
|
68
75
|
|
69
76
|
production:
|
@@ -79,7 +86,7 @@ doesn't know about.
|
|
79
86
|
:child_c:
|
80
87
|
:grandchild_a: 3
|
81
88
|
:grandchild_b: 4
|
82
|
-
:super_secret_password: not_that_secret
|
89
|
+
:super_secret_password: <%= ENV['SUPER_SECRET'] || 'not_that_secret' %>
|
83
90
|
:check: true
|
84
91
|
|
85
92
|
### test
|
@@ -90,7 +97,7 @@ doesn't know about.
|
|
90
97
|
:child_c:
|
91
98
|
:grandchild_a: 3
|
92
99
|
:grandchild_b: 4
|
93
|
-
:super_secret_password: not_that_secret
|
100
|
+
:super_secret_password: <%= ENV['SUPER_SECRET'] || 'not_that_secret' %>
|
94
101
|
:check: true
|
95
102
|
|
96
103
|
### production
|
@@ -101,7 +108,7 @@ doesn't know about.
|
|
101
108
|
:child_c:
|
102
109
|
:grandchild_a: 3
|
103
110
|
:grandchild_b: 4
|
104
|
-
:super_secret_password: cant_trust_dev_with_this_we_symlink_this_file
|
111
|
+
:super_secret_password: <%= ENV['SUPER_DUPER_SECRET'] || 'cant_trust_dev_with_this_we_symlink_this_file' %>
|
105
112
|
:check: true
|
106
113
|
|
107
114
|
### staging
|
data/lib/hierarchical_config.rb
CHANGED
@@ -65,9 +65,16 @@ module HierarchicalConfig
|
|
65
65
|
ordered_stanza_labels += yaml_config.keys.grep(/^defaults\[.*#{environment}/).sort_by{ |a| a.count(',') }
|
66
66
|
ordered_stanza_labels << environment if yaml_config.key? environment
|
67
67
|
|
68
|
-
config = ordered_stanza_labels
|
69
|
-
|
70
|
-
|
68
|
+
config = deep_merge_hashes_in_keys(ordered_stanza_labels, yaml_config)
|
69
|
+
|
70
|
+
env_config_labels = []
|
71
|
+
env_config_labels << 'env_vars' if yaml_config.key? 'env_vars'
|
72
|
+
env_config_labels += yaml_config.keys.grep(/^env_vars\[.*#{environment}/).sort_by{ |a| a.count(',') }
|
73
|
+
|
74
|
+
env_config = deep_merge_hashes_in_keys(env_config_labels, yaml_config)
|
75
|
+
env_config = fill_in_env_vars(env_config)
|
76
|
+
|
77
|
+
deep_merge(config, env_config)
|
71
78
|
|
72
79
|
rescue StandardError => e
|
73
80
|
raise <<-ERROR
|
@@ -79,6 +86,25 @@ module HierarchicalConfig
|
|
79
86
|
|
80
87
|
private
|
81
88
|
|
89
|
+
def deep_merge_hashes_in_keys(keys, root_hash)
|
90
|
+
keys.inject({}) do |acc, label|
|
91
|
+
deep_merge( acc, root_hash[label] )
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def fill_in_env_vars(hash)
|
96
|
+
r = {}
|
97
|
+
hash.each do |key,value|
|
98
|
+
if !value.nil? && ENV.key?(value)
|
99
|
+
r[key]=ENV[value]
|
100
|
+
elsif value.is_a? Hash
|
101
|
+
leaf_hash = fill_in_env_vars(value)
|
102
|
+
r[key]=leaf_hash unless leaf_hash.keys.empty?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
r
|
106
|
+
end
|
107
|
+
|
82
108
|
# merges two hashes with nested hashes if present
|
83
109
|
def deep_merge( hash1, hash2 )
|
84
110
|
hash1 = hash1.dup
|
metadata
CHANGED
@@ -1,50 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierarchical_config
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- timgaleckas
|
9
13
|
- tjbladez
|
10
14
|
- jdfrens
|
11
15
|
autorequire:
|
12
16
|
bindir: bin
|
13
17
|
cert_chain: []
|
14
|
-
|
18
|
+
|
19
|
+
date: 2012-07-19 00:00:00 Z
|
15
20
|
dependencies: []
|
16
|
-
|
17
|
-
|
21
|
+
|
22
|
+
description: Robust strategy for defining the configuration accross environements, machines, clusters
|
18
23
|
email: tim@galeckas.com, nick@tjbladez.com
|
19
24
|
executables: []
|
25
|
+
|
20
26
|
extensions: []
|
27
|
+
|
21
28
|
extra_rdoc_files: []
|
22
|
-
|
29
|
+
|
30
|
+
files:
|
23
31
|
- lib/hierarchical_config.rb
|
24
32
|
- README.markdown
|
25
33
|
homepage: http://github.com/timgaleckas/hierarchical_config
|
26
34
|
licenses: []
|
35
|
+
|
27
36
|
post_install_message:
|
28
37
|
rdoc_options: []
|
29
|
-
|
38
|
+
|
39
|
+
require_paths:
|
30
40
|
- lib
|
31
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
42
|
none: false
|
33
|
-
requirements:
|
34
|
-
- -
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
|
37
|
-
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
51
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
43
59
|
requirements: []
|
60
|
+
|
44
61
|
rubyforge_project:
|
45
|
-
rubygems_version: 1.8.
|
62
|
+
rubygems_version: 1.8.21
|
46
63
|
signing_key:
|
47
64
|
specification_version: 3
|
48
|
-
summary: Robust strategy for defining the configuration accross environements, machines,
|
49
|
-
clusters
|
65
|
+
summary: Robust strategy for defining the configuration accross environements, machines, clusters
|
50
66
|
test_files: []
|
67
|
+
|
68
|
+
has_rdoc: false
|