hierarchical_config 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +25 -7
- data/lib/hierarchical_config.rb +6 -0
- metadata +4 -3
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## What is it
|
2
2
|
|
3
|
-
HierarchicalConfig is a library that
|
3
|
+
HierarchicalConfig is a library that implements a strategy for configuring an application in a static, declarative, robust, and intuitive way
|
4
4
|
|
5
5
|
## Principles
|
6
6
|
|
@@ -55,6 +55,7 @@ doesn't know about.
|
|
55
55
|
grandchild_a: 3
|
56
56
|
grandchild_b: 4
|
57
57
|
super_secret_password: !REQUIRED
|
58
|
+
check: true
|
58
59
|
|
59
60
|
defaults[development,test]:
|
60
61
|
super_secret_password: not_that_secret
|
@@ -72,34 +73,51 @@ doesn't know about.
|
|
72
73
|
|
73
74
|
### development
|
74
75
|
|
75
|
-
:root:
|
76
|
+
:root:
|
76
77
|
:child_a: 1
|
77
78
|
:child_b: 8
|
78
|
-
:child_c:
|
79
|
+
:child_c:
|
79
80
|
:grandchild_a: 3
|
80
81
|
:grandchild_b: 4
|
81
82
|
:super_secret_password: not_that_secret
|
83
|
+
:check: true
|
82
84
|
|
83
85
|
### test
|
84
86
|
|
85
|
-
:root:
|
87
|
+
:root:
|
86
88
|
:child_a: 1
|
87
89
|
:child_b: 2
|
88
|
-
:child_c:
|
90
|
+
:child_c:
|
89
91
|
:grandchild_a: 3
|
90
92
|
:grandchild_b: 4
|
91
93
|
:super_secret_password: not_that_secret
|
94
|
+
:check: true
|
92
95
|
|
93
96
|
### production
|
94
97
|
|
95
|
-
:root:
|
98
|
+
:root:
|
96
99
|
:child_a: 1
|
97
100
|
:child_b: 2
|
98
|
-
:child_c:
|
101
|
+
:child_c:
|
99
102
|
:grandchild_a: 3
|
100
103
|
:grandchild_b: 4
|
101
104
|
:super_secret_password: cant_trust_dev_with_this_we_symlink_this_file
|
105
|
+
:check: true
|
102
106
|
|
103
107
|
### staging
|
104
108
|
|
105
109
|
RuntimeError: ["app.super_secret_password is REQUIRED for staging"]
|
110
|
+
|
111
|
+
### Code
|
112
|
+
|
113
|
+
You can access children nodes with a method call or an index operator, in any combination. Add a `?` to the name of a node to get a boolean value back.
|
114
|
+
|
115
|
+
# in development environment
|
116
|
+
AppConfig = HierarchicalConfig.load_config('app', Rails.root.join('config'), Rails.env)
|
117
|
+
|
118
|
+
AppConfig.root.child_a # => 1
|
119
|
+
AppConfig.root["child_c"].grandchild_a # => 3
|
120
|
+
AppConfig[:super_secret_password] # => 'not_that_secret'
|
121
|
+
AppConfig.check # => true
|
122
|
+
AppConfig.check? # => true
|
123
|
+
AppConfig.super_secret_password? # => true
|
data/lib/hierarchical_config.rb
CHANGED
@@ -16,6 +16,8 @@ module HierarchicalConfig
|
|
16
16
|
raise ArgumentError, "wrong number of arguments (#{len} for 1)", caller(1)
|
17
17
|
end
|
18
18
|
modifiable[new_ostruct_member(mname)] = args[0]
|
19
|
+
elsif mname =~ /\?$/
|
20
|
+
!!send(mname.gsub("?",""))
|
19
21
|
elsif len == 0 && @table.key?( mid )
|
20
22
|
@table[mid]
|
21
23
|
else
|
@@ -23,6 +25,10 @@ module HierarchicalConfig
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
28
|
+
def [](attribute)
|
29
|
+
send(attribute)
|
30
|
+
end
|
31
|
+
|
26
32
|
def to_hash
|
27
33
|
@table.inject({}) do |hash, key_value|
|
28
34
|
key, value = *key_value
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierarchical_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- timgaleckas
|
9
9
|
- tjbladez
|
10
|
+
- jdfrens
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2011-
|
14
|
+
date: 2011-12-14 00:00:00.000000000Z
|
14
15
|
dependencies: []
|
15
16
|
description: Robust strategy for defining the configuration accross environements,
|
16
17
|
machines, clusters
|
@@ -41,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
42
|
version: '0'
|
42
43
|
requirements: []
|
43
44
|
rubyforge_project:
|
44
|
-
rubygems_version: 1.8.
|
45
|
+
rubygems_version: 1.8.10
|
45
46
|
signing_key:
|
46
47
|
specification_version: 3
|
47
48
|
summary: Robust strategy for defining the configuration accross environements, machines,
|