rconfig 0.4.2 → 0.4.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/ChangeLog +7 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/Rakefile +11 -8
- data/doc/Array.html +184 -0
- data/doc/Hash.html +360 -0
- data/doc/NilClass.html +233 -0
- data/doc/RConfig.html +328 -0
- data/doc/RConfig/Callbacks.html +295 -0
- data/doc/RConfig/Cascade.html +316 -0
- data/doc/RConfig/Config.html +441 -0
- data/doc/RConfig/ConfigError.html +187 -0
- data/doc/RConfig/Constants.html +271 -0
- data/doc/RConfig/CoreMethods.html +814 -0
- data/doc/RConfig/DisabledLogger.html +424 -0
- data/doc/RConfig/Exceptions.html +266 -0
- data/doc/RConfig/Generators.html +186 -0
- data/doc/RConfig/Generators/InstallGenerator.html +233 -0
- data/doc/RConfig/InvalidLoadPathError.html +187 -0
- data/doc/RConfig/LoadPaths.html +375 -0
- data/doc/RConfig/Logger.html +184 -0
- data/doc/RConfig/PropertiesFile.html +399 -0
- data/doc/RConfig/Reload.html +481 -0
- data/doc/RConfig/Settings.html +188 -0
- data/doc/RConfig/Utils.html +841 -0
- data/doc/README_rdoc.html +331 -0
- data/doc/String.html +184 -0
- data/doc/created.rid +21 -1
- data/doc/index.html +423 -20
- data/doc/lib/generators/rconfig/install_generator_rb.html +52 -0
- data/doc/lib/generators/rconfig/templates/rconfig_rb.html +56 -0
- data/doc/lib/rconfig/callbacks_rb.html +52 -0
- data/doc/lib/rconfig/cascade_rb.html +52 -0
- data/doc/lib/rconfig/config_rb.html +61 -0
- data/doc/lib/rconfig/constants_rb.html +52 -0
- data/doc/lib/rconfig/core_ext/array_rb.html +52 -0
- data/doc/lib/rconfig/core_ext/hash_rb.html +61 -0
- data/doc/lib/rconfig/core_ext/nil_rb.html +52 -0
- data/doc/lib/rconfig/core_ext/string_rb.html +52 -0
- data/doc/lib/rconfig/core_methods_rb.html +55 -0
- data/doc/lib/rconfig/exceptions_rb.html +58 -0
- data/doc/lib/rconfig/load_paths_rb.html +52 -0
- data/doc/lib/rconfig/logger_rb.html +52 -0
- data/doc/lib/rconfig/properties_file_rb.html +93 -0
- data/doc/lib/rconfig/reload_rb.html +52 -0
- data/doc/lib/rconfig/settings_rb.html +52 -0
- data/doc/lib/rconfig/utils_rb.html +52 -0
- data/doc/lib/rconfig_rb.html +151 -0
- data/doc/rdoc.css +706 -0
- data/lib/rconfig.rb +1 -1
- data/lib/rconfig/load_paths.rb +2 -2
- data/lib/tasks/rdoc.rake +3 -4
- data/rconfig.gemspec +4 -2
- data/spec/config/erb_contents.yml +3 -0
- data/spec/config/props_config.conf +18 -0
- data/spec/config/spec.yml +17 -0
- data/spec/config/xml_config.xml +22 -0
- data/spec/config2/.gitkeep +0 -0
- data/spec/rconfig/load_paths_spec.rb +37 -0
- data/spec/rconfig/reload_spec.rb +37 -0
- data/spec/rconfig_spec.rb +61 -3
- data/spec/spec_helper.rb +12 -8
- metadata +82 -40
- data/doc/classes/ClassVariables.html +0 -111
- data/doc/classes/ConfigError.html +0 -120
- data/doc/classes/ConfigHash.html +0 -354
- data/doc/classes/Constants.html +0 -226
- data/doc/classes/Hash.html +0 -269
- data/doc/classes/InvalidConfigPathError.html +0 -119
- data/doc/classes/Object.html +0 -220
- data/doc/classes/PropertiesFileParser.html +0 -282
- data/doc/classes/RConfig.html +0 -1745
- data/doc/files/README_rdoc.html +0 -271
- data/doc/files/lib/rconfig/class_variables_rb.html +0 -107
- data/doc/files/lib/rconfig/config_hash_rb.html +0 -114
- data/doc/files/lib/rconfig/constants_rb.html +0 -101
- data/doc/files/lib/rconfig/core_ext/hash_rb.html +0 -114
- data/doc/files/lib/rconfig/core_ext/object_rb.html +0 -101
- data/doc/files/lib/rconfig/core_ext_rb.html +0 -114
- data/doc/files/lib/rconfig/exceptions_rb.html +0 -110
- data/doc/files/lib/rconfig/properties_file_parser_rb.html +0 -146
- data/doc/files/lib/rconfig/rconfig_rb.html +0 -186
- data/doc/files/lib/rconfig_rb.html +0 -117
- data/doc/fr_class_index.html +0 -35
- data/doc/fr_file_index.html +0 -37
- data/doc/fr_method_index.html +0 -75
- data/doc/rdoc-style.css +0 -208
- data/lib/tasks/gem.rake +0 -14
- data/lib/tasks/spec.rake +0 -25
- data/spec/core_ext/object_spec.rb +0 -44
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
2
|
-
<!DOCTYPE html
|
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
5
|
-
|
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
7
|
-
<head>
|
|
8
|
-
<title>Class: InvalidConfigPathError</title>
|
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
|
12
|
-
<script type="text/javascript">
|
|
13
|
-
// <![CDATA[
|
|
14
|
-
|
|
15
|
-
function popupCode( url ) {
|
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function toggleCode( id ) {
|
|
20
|
-
if ( document.getElementById )
|
|
21
|
-
elem = document.getElementById( id );
|
|
22
|
-
else if ( document.all )
|
|
23
|
-
elem = eval( "document.all." + id );
|
|
24
|
-
else
|
|
25
|
-
return false;
|
|
26
|
-
|
|
27
|
-
elemStyle = elem.style;
|
|
28
|
-
|
|
29
|
-
if ( elemStyle.display != "block" ) {
|
|
30
|
-
elemStyle.display = "block"
|
|
31
|
-
} else {
|
|
32
|
-
elemStyle.display = "none"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Make codeblocks hidden by default
|
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
40
|
-
|
|
41
|
-
// ]]>
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
</head>
|
|
45
|
-
<body>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<div id="classHeader">
|
|
50
|
-
<table class="header-table">
|
|
51
|
-
<tr class="top-aligned-row">
|
|
52
|
-
<td><strong>Class</strong></td>
|
|
53
|
-
<td class="class-name-in-header">InvalidConfigPathError</td>
|
|
54
|
-
</tr>
|
|
55
|
-
<tr class="top-aligned-row">
|
|
56
|
-
<td><strong>In:</strong></td>
|
|
57
|
-
<td>
|
|
58
|
-
<a href="../files/lib/rconfig/exceptions_rb.html">
|
|
59
|
-
lib/rconfig/exceptions.rb
|
|
60
|
-
</a>
|
|
61
|
-
<br />
|
|
62
|
-
</td>
|
|
63
|
-
</tr>
|
|
64
|
-
|
|
65
|
-
<tr class="top-aligned-row">
|
|
66
|
-
<td><strong>Parent:</strong></td>
|
|
67
|
-
<td>
|
|
68
|
-
<a href="ConfigError.html">
|
|
69
|
-
ConfigError
|
|
70
|
-
</a>
|
|
71
|
-
</td>
|
|
72
|
-
</tr>
|
|
73
|
-
</table>
|
|
74
|
-
</div>
|
|
75
|
-
<!-- banner header -->
|
|
76
|
-
|
|
77
|
-
<div id="bodyContent">
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<div id="contextContent">
|
|
82
|
-
|
|
83
|
-
<div id="description">
|
|
84
|
-
<p>
|
|
85
|
-
Config path(s) are not set, don‘t exist, or Invalid in some manner
|
|
86
|
-
</p>
|
|
87
|
-
|
|
88
|
-
</div>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
</div>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
<!-- if includes -->
|
|
98
|
-
|
|
99
|
-
<div id="section">
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
<!-- if method_list -->
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
</div>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
<div id="validator-badges">
|
|
115
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
116
|
-
</div>
|
|
117
|
-
|
|
118
|
-
</body>
|
|
119
|
-
</html>
|
data/doc/classes/Object.html
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
2
|
-
<!DOCTYPE html
|
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
5
|
-
|
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
7
|
-
<head>
|
|
8
|
-
<title>Class: Object</title>
|
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
|
12
|
-
<script type="text/javascript">
|
|
13
|
-
// <![CDATA[
|
|
14
|
-
|
|
15
|
-
function popupCode( url ) {
|
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function toggleCode( id ) {
|
|
20
|
-
if ( document.getElementById )
|
|
21
|
-
elem = document.getElementById( id );
|
|
22
|
-
else if ( document.all )
|
|
23
|
-
elem = eval( "document.all." + id );
|
|
24
|
-
else
|
|
25
|
-
return false;
|
|
26
|
-
|
|
27
|
-
elemStyle = elem.style;
|
|
28
|
-
|
|
29
|
-
if ( elemStyle.display != "block" ) {
|
|
30
|
-
elemStyle.display = "block"
|
|
31
|
-
} else {
|
|
32
|
-
elemStyle.display = "none"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Make codeblocks hidden by default
|
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
40
|
-
|
|
41
|
-
// ]]>
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
</head>
|
|
45
|
-
<body>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<div id="classHeader">
|
|
50
|
-
<table class="header-table">
|
|
51
|
-
<tr class="top-aligned-row">
|
|
52
|
-
<td><strong>Class</strong></td>
|
|
53
|
-
<td class="class-name-in-header">Object</td>
|
|
54
|
-
</tr>
|
|
55
|
-
<tr class="top-aligned-row">
|
|
56
|
-
<td><strong>In:</strong></td>
|
|
57
|
-
<td>
|
|
58
|
-
<a href="../files/lib/rconfig/core_ext/object_rb.html">
|
|
59
|
-
lib/rconfig/core_ext/object.rb
|
|
60
|
-
</a>
|
|
61
|
-
<br />
|
|
62
|
-
</td>
|
|
63
|
-
</tr>
|
|
64
|
-
|
|
65
|
-
<tr class="top-aligned-row">
|
|
66
|
-
<td><strong>Parent:</strong></td>
|
|
67
|
-
<td>
|
|
68
|
-
<a href="Object.html">
|
|
69
|
-
Object
|
|
70
|
-
</a>
|
|
71
|
-
</td>
|
|
72
|
-
</tr>
|
|
73
|
-
</table>
|
|
74
|
-
</div>
|
|
75
|
-
<!-- banner header -->
|
|
76
|
-
|
|
77
|
-
<div id="bodyContent">
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<div id="contextContent">
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
</div>
|
|
86
|
-
|
|
87
|
-
<div id="method-list">
|
|
88
|
-
<h3 class="section-bar">Methods</h3>
|
|
89
|
-
|
|
90
|
-
<div class="name-list">
|
|
91
|
-
<a href="#M000002">config</a>
|
|
92
|
-
<a href="#M000001">try</a>
|
|
93
|
-
</div>
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
</div>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<!-- if includes -->
|
|
100
|
-
|
|
101
|
-
<div id="section">
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
<!-- if method_list -->
|
|
111
|
-
<div id="methods">
|
|
112
|
-
<h3 class="section-bar">Public Instance methods</h3>
|
|
113
|
-
|
|
114
|
-
<div id="method-M000002" class="method-detail">
|
|
115
|
-
<a name="M000002"></a>
|
|
116
|
-
|
|
117
|
-
<div class="method-heading">
|
|
118
|
-
<a href="#M000002" class="method-signature">
|
|
119
|
-
<span class="method-name">config</span><span class="method-args">()</span>
|
|
120
|
-
</a>
|
|
121
|
-
</div>
|
|
122
|
-
|
|
123
|
-
<div class="method-description">
|
|
124
|
-
<p>
|
|
125
|
-
Convience method for short-hand access to class specific <a
|
|
126
|
-
href="Object.html#M000002">config</a>. If a <a
|
|
127
|
-
href="Object.html#M000002">config</a> specific to this class doesn‘t
|
|
128
|
-
exist, it‘ll return the root <a href="Object.html#M000002">config</a>
|
|
129
|
-
instance.
|
|
130
|
-
</p>
|
|
131
|
-
<p>
|
|
132
|
-
Example:
|
|
133
|
-
</p>
|
|
134
|
-
<pre>
|
|
135
|
-
# Given CONFIG_PATH/person.yml (with param sort_by_lastname: true)
|
|
136
|
-
@person = Person.new
|
|
137
|
-
@person.config => $config.person
|
|
138
|
-
@person.config.sort_by_lastname => true
|
|
139
|
-
|
|
140
|
-
# Given CONFIG_PATH/bank_account.yml (with param mask_account_number: true)
|
|
141
|
-
bank_acct = BankAccount.new
|
|
142
|
-
bank_acct.config => $config.bank_account
|
|
143
|
-
bank_acct.config.mask_account_number => true
|
|
144
|
-
|
|
145
|
-
# Given no specific config
|
|
146
|
-
@person = Person.new
|
|
147
|
-
@person.config => $config
|
|
148
|
-
@person.config.bank_account => $config.bank_account
|
|
149
|
-
</pre>
|
|
150
|
-
<p>
|
|
151
|
-
NOTE: If there is a class-specific <a href="Object.html#M000002">config</a>
|
|
152
|
-
file, and an object needs to
|
|
153
|
-
</p>
|
|
154
|
-
<pre>
|
|
155
|
-
access a different config, use the global instance ($config) or
|
|
156
|
-
the class (RConfig).
|
|
157
|
-
</pre>
|
|
158
|
-
<p><a class="source-toggle" href="#"
|
|
159
|
-
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
|
160
|
-
<div class="method-source-code" id="M000002-source">
|
|
161
|
-
<pre>
|
|
162
|
-
<span class="ruby-comment cmt"># File lib/rconfig/core_ext/object.rb, line 41</span>
|
|
163
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">config</span>
|
|
164
|
-
<span class="ruby-identifier">this_config</span> = <span class="ruby-identifier">$config</span>.<span class="ruby-identifier">send</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">name</span>.<span class="ruby-identifier">underscore</span>.<span class="ruby-identifier">to_sym</span>)
|
|
165
|
-
<span class="ruby-identifier">this_config</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-value">? </span><span class="ruby-identifier">$config</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">this_config</span>
|
|
166
|
-
<span class="ruby-keyword kw">end</span>
|
|
167
|
-
</pre>
|
|
168
|
-
</div>
|
|
169
|
-
</div>
|
|
170
|
-
</div>
|
|
171
|
-
|
|
172
|
-
<div id="method-M000001" class="method-detail">
|
|
173
|
-
<a name="M000001"></a>
|
|
174
|
-
|
|
175
|
-
<div class="method-heading">
|
|
176
|
-
<a href="#M000001" class="method-signature">
|
|
177
|
-
<span class="method-name">try</span><span class="method-args">(method, *args)</span>
|
|
178
|
-
</a>
|
|
179
|
-
</div>
|
|
180
|
-
|
|
181
|
-
<div class="method-description">
|
|
182
|
-
<pre>
|
|
183
|
-
@person ? @person.name : nil
|
|
184
|
-
- or -
|
|
185
|
-
</pre>
|
|
186
|
-
<p>
|
|
187
|
-
@people[:email] if @people
|
|
188
|
-
</p>
|
|
189
|
-
<pre>
|
|
190
|
-
- vs -
|
|
191
|
-
@person.try(:name)
|
|
192
|
-
</pre>
|
|
193
|
-
<p><a class="source-toggle" href="#"
|
|
194
|
-
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
|
195
|
-
<div class="method-source-code" id="M000001-source">
|
|
196
|
-
<pre>
|
|
197
|
-
<span class="ruby-comment cmt"># File lib/rconfig/core_ext/object.rb, line 9</span>
|
|
198
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">try</span>(<span class="ruby-identifier">method</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
|
199
|
-
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">send</span>(<span class="ruby-identifier">method</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">method</span>)
|
|
200
|
-
<span class="ruby-identifier">result</span> = <span class="ruby-identifier">send</span>(<span class="ruby-identifier">:[]</span>, <span class="ruby-identifier">method</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:[]</span>)
|
|
201
|
-
<span class="ruby-identifier">result</span>
|
|
202
|
-
<span class="ruby-keyword kw">end</span>
|
|
203
|
-
</pre>
|
|
204
|
-
</div>
|
|
205
|
-
</div>
|
|
206
|
-
</div>
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
</div>
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
</div>
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
<div id="validator-badges">
|
|
216
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
217
|
-
</div>
|
|
218
|
-
|
|
219
|
-
</body>
|
|
220
|
-
</html>
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
2
|
-
<!DOCTYPE html
|
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
5
|
-
|
|
6
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
7
|
-
<head>
|
|
8
|
-
<title>Class: PropertiesFileParser</title>
|
|
9
|
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
|
10
|
-
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
|
11
|
-
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
|
12
|
-
<script type="text/javascript">
|
|
13
|
-
// <![CDATA[
|
|
14
|
-
|
|
15
|
-
function popupCode( url ) {
|
|
16
|
-
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function toggleCode( id ) {
|
|
20
|
-
if ( document.getElementById )
|
|
21
|
-
elem = document.getElementById( id );
|
|
22
|
-
else if ( document.all )
|
|
23
|
-
elem = eval( "document.all." + id );
|
|
24
|
-
else
|
|
25
|
-
return false;
|
|
26
|
-
|
|
27
|
-
elemStyle = elem.style;
|
|
28
|
-
|
|
29
|
-
if ( elemStyle.display != "block" ) {
|
|
30
|
-
elemStyle.display = "block"
|
|
31
|
-
} else {
|
|
32
|
-
elemStyle.display = "none"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Make codeblocks hidden by default
|
|
39
|
-
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
|
40
|
-
|
|
41
|
-
// ]]>
|
|
42
|
-
</script>
|
|
43
|
-
|
|
44
|
-
</head>
|
|
45
|
-
<body>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<div id="classHeader">
|
|
50
|
-
<table class="header-table">
|
|
51
|
-
<tr class="top-aligned-row">
|
|
52
|
-
<td><strong>Class</strong></td>
|
|
53
|
-
<td class="class-name-in-header">PropertiesFileParser</td>
|
|
54
|
-
</tr>
|
|
55
|
-
<tr class="top-aligned-row">
|
|
56
|
-
<td><strong>In:</strong></td>
|
|
57
|
-
<td>
|
|
58
|
-
<a href="../files/lib/rconfig/properties_file_parser_rb.html">
|
|
59
|
-
lib/rconfig/properties_file_parser.rb
|
|
60
|
-
</a>
|
|
61
|
-
<br />
|
|
62
|
-
</td>
|
|
63
|
-
</tr>
|
|
64
|
-
|
|
65
|
-
<tr class="top-aligned-row">
|
|
66
|
-
<td><strong>Parent:</strong></td>
|
|
67
|
-
<td>
|
|
68
|
-
<a href="Object.html">
|
|
69
|
-
Object
|
|
70
|
-
</a>
|
|
71
|
-
</td>
|
|
72
|
-
</tr>
|
|
73
|
-
</table>
|
|
74
|
-
</div>
|
|
75
|
-
<!-- banner header -->
|
|
76
|
-
|
|
77
|
-
<div id="bodyContent">
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<div id="contextContent">
|
|
82
|
-
|
|
83
|
-
<div id="description">
|
|
84
|
-
<p>
|
|
85
|
-
Copyright (c) 2009 Rahmal Conda <rahmal@gmail.com>
|
|
86
|
-
</p>
|
|
87
|
-
<p>
|
|
88
|
-
This class parses key/value based properties files used for configuration.
|
|
89
|
-
It is used by rconfig to import configuration files of the aforementioned
|
|
90
|
-
format. Unlike yaml, and xml files it can only support three levels. First,
|
|
91
|
-
it can have root level properties:
|
|
92
|
-
</p>
|
|
93
|
-
<pre>
|
|
94
|
-
server_url=host.domain.com
|
|
95
|
-
server_port=8080
|
|
96
|
-
</pre>
|
|
97
|
-
<p>
|
|
98
|
-
Secondly, it can have properties grouped into catagories. The group names
|
|
99
|
-
must be specified within brackets like [ … ]
|
|
100
|
-
</p>
|
|
101
|
-
<pre>
|
|
102
|
-
[server]
|
|
103
|
-
url=host.domain.com
|
|
104
|
-
port=8080
|
|
105
|
-
</pre>
|
|
106
|
-
<p>
|
|
107
|
-
Finally, groups can also be qualified with namespaces, similar to git
|
|
108
|
-
config files. Group names are same as before, but with namespace in within
|
|
109
|
-
the brackets like [ <group> "<name>" ]
|
|
110
|
-
</p>
|
|
111
|
-
<pre>
|
|
112
|
-
[host "dev"]
|
|
113
|
-
domain=dev.server.com
|
|
114
|
-
|
|
115
|
-
[host "prod"]
|
|
116
|
-
domain=www.server.com
|
|
117
|
-
</pre>
|
|
118
|
-
<p>
|
|
119
|
-
These can be retrieved using dot-notation or variable to do it dynamically.
|
|
120
|
-
</p>
|
|
121
|
-
<pre>
|
|
122
|
-
RConfig.props.host.dev.domain
|
|
123
|
-
- or -
|
|
124
|
-
RConfig.props.host[env].domain (where env is 'dev' or 'prod')
|
|
125
|
-
</pre>
|
|
126
|
-
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
</div>
|
|
131
|
-
|
|
132
|
-
<div id="method-list">
|
|
133
|
-
<h3 class="section-bar">Methods</h3>
|
|
134
|
-
|
|
135
|
-
<div class="name-list">
|
|
136
|
-
<a href="#M000003">parse</a>
|
|
137
|
-
</div>
|
|
138
|
-
</div>
|
|
139
|
-
|
|
140
|
-
</div>
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
<!-- if includes -->
|
|
144
|
-
<div id="includes">
|
|
145
|
-
<h3 class="section-bar">Included Modules</h3>
|
|
146
|
-
|
|
147
|
-
<div id="includes-list">
|
|
148
|
-
<span class="include-name">Singleton</span>
|
|
149
|
-
</div>
|
|
150
|
-
</div>
|
|
151
|
-
|
|
152
|
-
<div id="section">
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
<div id="constants-list">
|
|
156
|
-
<h3 class="section-bar">Constants</h3>
|
|
157
|
-
|
|
158
|
-
<div class="name-list">
|
|
159
|
-
<table summary="Constants">
|
|
160
|
-
<tr class="top-aligned-row context-row">
|
|
161
|
-
<td class="context-item-name">COMMENT</td>
|
|
162
|
-
<td>=</td>
|
|
163
|
-
<td class="context-item-value">/^\#/</td>
|
|
164
|
-
</tr>
|
|
165
|
-
<tr class="top-aligned-row context-row">
|
|
166
|
-
<td class="context-item-name">KEYVAL</td>
|
|
167
|
-
<td>=</td>
|
|
168
|
-
<td class="context-item-value">/\s*=\s*/</td>
|
|
169
|
-
</tr>
|
|
170
|
-
<tr class="top-aligned-row context-row">
|
|
171
|
-
<td class="context-item-name">QUOTES</td>
|
|
172
|
-
<td>=</td>
|
|
173
|
-
<td class="context-item-value">/^['"](.*)['"]$/</td>
|
|
174
|
-
</tr>
|
|
175
|
-
<tr class="top-aligned-row context-row">
|
|
176
|
-
<td class="context-item-name">GROUP</td>
|
|
177
|
-
<td>=</td>
|
|
178
|
-
<td class="context-item-value">/^\[(.+)\]$/</td>
|
|
179
|
-
</tr>
|
|
180
|
-
<tr class="top-aligned-row context-row">
|
|
181
|
-
<td class="context-item-name">NAMEGRP</td>
|
|
182
|
-
<td>=</td>
|
|
183
|
-
<td class="context-item-value">/^\[(.+) \"(.+)\"\]$/</td>
|
|
184
|
-
</tr>
|
|
185
|
-
</table>
|
|
186
|
-
</div>
|
|
187
|
-
</div>
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
<!-- if method_list -->
|
|
195
|
-
<div id="methods">
|
|
196
|
-
<h3 class="section-bar">Public Class methods</h3>
|
|
197
|
-
|
|
198
|
-
<div id="method-M000003" class="method-detail">
|
|
199
|
-
<a name="M000003"></a>
|
|
200
|
-
|
|
201
|
-
<div class="method-heading">
|
|
202
|
-
<a href="#M000003" class="method-signature">
|
|
203
|
-
<span class="method-name">parse</span><span class="method-args">(config_file)</span>
|
|
204
|
-
</a>
|
|
205
|
-
</div>
|
|
206
|
-
|
|
207
|
-
<div class="method-description">
|
|
208
|
-
<p>
|
|
209
|
-
Parse config file and import data into hash to be stored in config.
|
|
210
|
-
</p>
|
|
211
|
-
<p><a class="source-toggle" href="#"
|
|
212
|
-
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
|
213
|
-
<div class="method-source-code" id="M000003-source">
|
|
214
|
-
<pre>
|
|
215
|
-
<span class="ruby-comment cmt"># File lib/rconfig/properties_file_parser.rb, line 47</span>
|
|
216
|
-
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">parse</span> <span class="ruby-identifier">config_file</span>
|
|
217
|
-
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">'Invalid config file name.'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">config_file</span>
|
|
218
|
-
|
|
219
|
-
<span class="ruby-identifier">config</span> = {}
|
|
220
|
-
|
|
221
|
-
<span class="ruby-comment cmt"># The config is top down.. anything after a [group] gets added as part</span>
|
|
222
|
-
<span class="ruby-comment cmt"># of that group until a new [group] is found. </span>
|
|
223
|
-
<span class="ruby-identifier">group</span>, <span class="ruby-identifier">topgrp</span> = <span class="ruby-keyword kw">nil</span>
|
|
224
|
-
<span class="ruby-identifier">config_file</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-comment cmt"># for each line in the config file</span>
|
|
225
|
-
<span class="ruby-identifier">line</span>.<span class="ruby-identifier">strip!</span>
|
|
226
|
-
<span class="ruby-keyword kw">unless</span> (<span class="ruby-constant">COMMENT</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">line</span>)) <span class="ruby-comment cmt"># skip comments (lines that state with '#')</span>
|
|
227
|
-
<span class="ruby-keyword kw">if</span>(<span class="ruby-constant">KEYVAL</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">line</span>)) <span class="ruby-comment cmt"># if this line is a config property</span>
|
|
228
|
-
<span class="ruby-identifier">key</span>, <span class="ruby-identifier">val</span> = <span class="ruby-identifier">line</span>.<span class="ruby-identifier">split</span>(<span class="ruby-constant">KEYVAL</span>, <span class="ruby-value">2</span>) <span class="ruby-comment cmt"># parse key and value from line</span>
|
|
229
|
-
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">strip</span>
|
|
230
|
-
<span class="ruby-identifier">val</span> = <span class="ruby-identifier">val</span>.<span class="ruby-identifier">chomp</span>.<span class="ruby-identifier">strip</span>
|
|
231
|
-
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">val</span>)
|
|
232
|
-
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">QUOTES</span> <span class="ruby-comment cmt"># if the value is in quotes</span>
|
|
233
|
-
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">$1</span> <span class="ruby-comment cmt"># strip out value from quotes</span>
|
|
234
|
-
<span class="ruby-keyword kw">else</span>
|
|
235
|
-
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">val</span> <span class="ruby-comment cmt"># otherwise, leave as-is</span>
|
|
236
|
-
<span class="ruby-keyword kw">end</span>
|
|
237
|
-
<span class="ruby-keyword kw">else</span>
|
|
238
|
-
<span class="ruby-identifier">value</span> = <span class="ruby-value str">''</span> <span class="ruby-comment cmt"># if value was nil, set it to empty string</span>
|
|
239
|
-
<span class="ruby-keyword kw">end</span>
|
|
240
|
-
|
|
241
|
-
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">topgrp</span> <span class="ruby-comment cmt"># If there was a top-level named group</span>
|
|
242
|
-
<span class="ruby-identifier">config</span>[<span class="ruby-identifier">topgrp</span>][<span class="ruby-identifier">group</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-comment cmt"># then there must be a group.</span>
|
|
243
|
-
<span class="ruby-identifier">value</span> <span class="ruby-comment cmt"># add the prop to the named group</span>
|
|
244
|
-
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">group</span> <span class="ruby-comment cmt"># if this property is part of a group</span>
|
|
245
|
-
<span class="ruby-identifier">config</span>[<span class="ruby-identifier">group</span>][<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span> <span class="ruby-comment cmt"># then add it to the group</span>
|
|
246
|
-
<span class="ruby-keyword kw">else</span>
|
|
247
|
-
<span class="ruby-identifier">config</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span> <span class="ruby-comment cmt"># otherwise, add it to top-level config</span>
|
|
248
|
-
<span class="ruby-keyword kw">end</span>
|
|
249
|
-
|
|
250
|
-
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">match</span> = <span class="ruby-constant">NAMEGRP</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">line</span>) <span class="ruby-comment cmt"># This line is a named group (i.e. [env "test"], [env "qa"], [env "production"])</span>
|
|
251
|
-
<span class="ruby-identifier">topgrp</span>, <span class="ruby-identifier">group</span> = <span class="ruby-identifier">match</span>.<span class="ruby-identifier">to_a</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-comment cmt"># There can be multiple groups within a single top-level group</span>
|
|
252
|
-
<span class="ruby-identifier">config</span>[<span class="ruby-identifier">topgrp</span>] <span class="ruby-operator">||=</span> {} <span class="ruby-comment cmt"># add group to top-level group</span>
|
|
253
|
-
<span class="ruby-identifier">config</span>[<span class="ruby-identifier">topgrp</span>][<span class="ruby-identifier">group</span>] <span class="ruby-operator">||=</span> {} <span class="ruby-comment cmt"># add name of group as subgroup (properties are added to subgroup)</span>
|
|
254
|
-
|
|
255
|
-
<span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">match</span> = <span class="ruby-constant">GROUP</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">line</span>) <span class="ruby-comment cmt"># if this line is a config group</span>
|
|
256
|
-
<span class="ruby-identifier">group</span> = <span class="ruby-identifier">match</span>.<span class="ruby-identifier">to_a</span>[<span class="ruby-value">1</span>] <span class="ruby-comment cmt"># parse the group name from line</span>
|
|
257
|
-
<span class="ruby-identifier">topgrp</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># we got a new group with no namespace, so reset topgrp</span>
|
|
258
|
-
<span class="ruby-identifier">config</span>[<span class="ruby-identifier">group</span>] <span class="ruby-operator">||=</span> {} <span class="ruby-comment cmt"># add group to top-level config</span>
|
|
259
|
-
<span class="ruby-keyword kw">end</span>
|
|
260
|
-
<span class="ruby-keyword kw">end</span>
|
|
261
|
-
<span class="ruby-keyword kw">end</span>
|
|
262
|
-
|
|
263
|
-
<span class="ruby-identifier">config</span> <span class="ruby-comment cmt"># return config hash</span>
|
|
264
|
-
<span class="ruby-keyword kw">end</span>
|
|
265
|
-
</pre>
|
|
266
|
-
</div>
|
|
267
|
-
</div>
|
|
268
|
-
</div>
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
</div>
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
</div>
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
<div id="validator-badges">
|
|
278
|
-
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
|
279
|
-
</div>
|
|
280
|
-
|
|
281
|
-
</body>
|
|
282
|
-
</html>
|