cascading-configuration-hash 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. data/README.md +365 -0
  2. data/README.rdoc +14 -100
  3. data/lib/cascading-configuration-hash.rb +18 -15
  4. data/lib/cascading-configuration-hash/CascadingConfiguration/{CascadingCompositeHash.rb → CompositingHash.rb} +3 -3
  5. data/lib/cascading-configuration-hash/CascadingConfiguration/{CascadingCompositeHash → CompositingHash}/Instance.rb +4 -2
  6. data/lib/cascading-configuration-hash/CascadingConfiguration/{CascadingCompositeHash → CompositingHash}/_private_/Instance.rb +1 -1
  7. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb +33 -0
  8. data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Accessors.rb +49 -0
  9. data/lib/cascading-configuration-hash/CascadingConfiguration/{ConfigurationSettingsHash → Hash}/ClassInstance.rb +3 -1
  10. data/lib/cascading-configuration-hash/CascadingConfiguration/{ConfigurationSettingsHash → Hash}/ModuleInstance.rb +7 -4
  11. data/lib/cascading-configuration-hash/CascadingConfiguration/{ConfigurationHash.rb → LocalConfigurationHash.rb} +2 -2
  12. data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/{CascadingCompositeHash.rb → CompositingHash.rb} +1 -1
  13. data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/{ConfigurationHash.rb → LocalConfigurationHash.rb} +3 -3
  14. data/spec/CascadingConfiguration/CascadingCompositeHash_spec.rb +57 -57
  15. data/spec/CascadingConfiguration/ConfigurationHash_spec.rb +8 -8
  16. data/spec/CascadingConfiguration/ConfigurationSettingsHash/Accessors_spec.rb +12 -12
  17. data/spec/CascadingConfiguration/ConfigurationSettingsHash_spec.rb +21 -21
  18. metadata +14 -13
  19. data/lib/cascading-configuration-hash/CascadingConfiguration/ConfigurationSettingsHash.rb +0 -21
  20. data/lib/cascading-configuration-hash/CascadingConfiguration/ConfigurationSettingsHash/Accessors.rb +0 -35
data/README.md ADDED
@@ -0,0 +1,365 @@
1
+ # Cascading Configuration #
2
+
3
+ http://rubygems.org/gems/cascading-configuration-hash
4
+
5
+ # Description #
6
+
7
+ Adds methods for cascading configuration hashes. Support package for cascading-configuration.
8
+
9
+ # Summary #
10
+
11
+ ## :attr_configuration_hash ##
12
+
13
+ :attr_configuration_hash provides inheritable configuration that cascades downward.
14
+
15
+ Configuration inheritance can cascade through modules, classes, and instances.
16
+
17
+ :attr_configuration_hash defines a single attribute accessor that composes the set of configuration values appropriate to the ancestor level being queried (merging downward from most distant ancestor to self). An internal cache is kept, and any configuration updates that occur to higher-level ancestors cascade immediately downward.
18
+
19
+ # Install #
20
+
21
+ * sudo gem install cascading-configuration-hash
22
+
23
+ # Usage #
24
+
25
+ ## First Module ##
26
+
27
+ 1. Define initial configuration in a module.
28
+
29
+ A class works just as well, but we can't use a module in the same chain if we start with a class.
30
+
31
+ * Include module to enable attr_configuration_hash.
32
+
33
+ ```ruby
34
+
35
+ module CascadingConfiguration::MockModule
36
+ include CascadingConfiguration::Hash
37
+ end
38
+
39
+ ```
40
+
41
+ * Declare attr_configuration_hash.
42
+
43
+ ```ruby
44
+
45
+ module CascadingConfiguration::MockModule
46
+ attr_configuration_hash :some_hash_configuration
47
+ end
48
+
49
+ ```
50
+
51
+ * Set initial value.
52
+
53
+ ```ruby
54
+
55
+ module CascadingConfiguration::MockModule
56
+ self.some_hash_configuration = { :some_value => :some_value }
57
+ end
58
+
59
+ ```
60
+
61
+ * Verify initial configuration value
62
+
63
+ ```ruby
64
+
65
+ module CascadingConfiguration::MockModule
66
+ # => some_hash_configuration.should == { :some_value => :some_value }
67
+ end
68
+
69
+ ```
70
+
71
+ ## Including Module 1 ##
72
+
73
+ 2. Include initial module in another module.
74
+
75
+ Including the module that has included a CascadingConfiguration module is the same as including a CascadingConfiguration module.
76
+
77
+ ```ruby
78
+
79
+ module CascadingConfiguration::MockModule2
80
+ include CascadingConfiguration::MockModule
81
+ end
82
+
83
+ ```
84
+
85
+ * Verify inherited value
86
+
87
+ ```ruby
88
+
89
+ module CascadingConfiguration::MockModule2
90
+ # => some_hash_configuration.should == { :some_value => :some_value }
91
+ end
92
+
93
+ ```
94
+
95
+ * Override inherited value
96
+
97
+ ```ruby
98
+
99
+ module CascadingConfiguration::MockModule2
100
+ self.some_hash_configuration = { :module_value => :some_value }
101
+ end
102
+
103
+ ```
104
+
105
+ * Verify local override value
106
+
107
+ ```ruby
108
+
109
+ module CascadingConfiguration::MockModule2
110
+ # => some_hash_configuration.should == { :module_value => :some_value }
111
+ end
112
+
113
+ ```
114
+
115
+ ## Including Module 2 ##
116
+
117
+ 3. Include second module in another module.
118
+
119
+ ```ruby
120
+
121
+ module CascadingConfiguration::MockModule3
122
+ include CascadingConfiguration::MockModule2
123
+ end
124
+
125
+ ```
126
+
127
+ * Verify inherited value
128
+
129
+ ```ruby
130
+
131
+ module CascadingConfiguration::MockModule3
132
+ # => some_array_configuration.should == { :module_value => :some_value }
133
+ end
134
+
135
+ ```
136
+
137
+ ## Top Class ##
138
+
139
+ 4. Include third module in a class.
140
+
141
+ ```ruby
142
+
143
+ class CascadingConfiguration::MockClass
144
+ include CascadingConfiguration::MockModule3
145
+ end
146
+
147
+ ```
148
+
149
+ * Verify inherited value
150
+
151
+ ```ruby
152
+
153
+ class CascadingConfiguration::MockClass
154
+ # => some_hash_configuration.should == { :module_value => :some_value }
155
+ end
156
+
157
+ ```
158
+
159
+ * Override inherited value
160
+
161
+ ```ruby
162
+
163
+ class CascadingConfiguration::MockClass
164
+ self.some_hash_configuration = { :another_value => :some_value }
165
+ end
166
+
167
+ ```
168
+
169
+ * Verify local override value
170
+
171
+ ```ruby
172
+
173
+ class CascadingConfiguration::MockClass
174
+ # => some_hash_configuration.should == { :another_value => :some_value }
175
+ end
176
+
177
+ ```
178
+
179
+ ## Instance of Top Class ##
180
+
181
+ 5. Instantiate class.
182
+
183
+ ```ruby
184
+
185
+ object_instance_one = CascadingConfiguration::MockClass.new
186
+
187
+ ```
188
+
189
+ * Verify inherited value
190
+
191
+ ```ruby
192
+
193
+ # => object_instance_one.some_hash_configuration.should == { :another_value => :some_value }
194
+
195
+ ```
196
+
197
+ * Override inherited value
198
+
199
+ ```ruby
200
+
201
+ object_instance_one.some_hash_configuration = { :yet_another_value => :some_value }
202
+
203
+ ```
204
+
205
+ * Verify local override value
206
+
207
+ ```ruby
208
+
209
+ # => object_instance_one.some_hash_configuration.should == { :yet_another_value => :some_value }
210
+ # => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
211
+ # => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
212
+
213
+ ```
214
+
215
+ # First Inheriting Class #
216
+
217
+ 6. Inheriting class.
218
+
219
+ Inheriting class should not get any settings from instance of superclass.
220
+
221
+ * Verify inherited value
222
+
223
+ ```ruby
224
+
225
+ class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
226
+ # => some_hash_configuration.should == { :another_value => :some_value }
227
+ end
228
+
229
+ ```
230
+
231
+ * Override inherited value
232
+
233
+ ```ruby
234
+
235
+ class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
236
+ self.some_hash_configuration = { :a_value_not_yet_used => :some_value }
237
+ end
238
+
239
+ ```
240
+
241
+ * Verify local override value
242
+
243
+ ```ruby
244
+
245
+ class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
246
+ # => some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
247
+ # => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
248
+ # => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
249
+ end
250
+
251
+ ```
252
+
253
+ ## Instance of First Inheriting Class ##
254
+
255
+ 7. Instantiate first inheriting class.
256
+
257
+ ```ruby
258
+
259
+ object_instance_two = CascadingConfiguration::MockClassSub1.new
260
+
261
+ ```
262
+
263
+ * Verify inherited value
264
+
265
+ ```ruby
266
+
267
+ # => object_instance_two.some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
268
+ # => object_instance_one.some_hash_configuration.should == { :yet_another_value => :some_value }
269
+ # => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
270
+ # => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
271
+
272
+ ```
273
+
274
+ ## Second Inheriting Class ##
275
+
276
+ 8. Second inheriting class.
277
+
278
+ * Verify inherited value
279
+
280
+ ```ruby
281
+
282
+ class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
283
+ # => some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
284
+ end
285
+
286
+ ```
287
+
288
+ * Override inherited value
289
+
290
+ ```ruby
291
+
292
+ class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
293
+ self.some_hash_configuration = { :another_value_not_yet_used => :some_value }
294
+ end
295
+
296
+ ```
297
+
298
+ * Verify local override value
299
+
300
+ ```ruby
301
+
302
+ class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
303
+ # => some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
304
+ end
305
+
306
+ ```
307
+
308
+ ## Instance of Second Inheriting Class ##
309
+
310
+ 9. Instantiate Second Inheriting Class.
311
+
312
+ ```ruby
313
+
314
+ object_instance_three = CascadingConfiguration::MockClassSub2.new
315
+
316
+ ```
317
+
318
+ * Verify inherited value
319
+
320
+ ```ruby
321
+
322
+ # => object_instance_three.some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
323
+
324
+ ```
325
+
326
+ * Override inherited value
327
+
328
+ ```ruby
329
+
330
+ object_instance_three.some_hash_configuration = { :one_more_unused_value => :some_value }
331
+
332
+ ```
333
+
334
+ * Verify local override value
335
+
336
+ ```ruby
337
+
338
+ # => object_instance_three.some_hash_configuration.should == { :one_more_unused_value => :some_value }
339
+
340
+ ```
341
+
342
+ # License #
343
+
344
+ (The MIT License)
345
+
346
+ Copyright (c) 2011 Asher
347
+
348
+ Permission is hereby granted, free of charge, to any person obtaining
349
+ a copy of this software and associated documentation files (the
350
+ 'Software'), to deal in the Software without restriction, including
351
+ without limitation the rights to use, copy, modify, merge, publish,
352
+ distribute, sublicense, and/or sell copies of the Software, and to
353
+ permit persons to whom the Software is furnished to do so, subject to
354
+ the following conditions:
355
+
356
+ The above copyright notice and this permission notice shall be
357
+ included in all copies or substantial portions of the Software.
358
+
359
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
360
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
361
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
362
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
363
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
364
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
365
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -1,118 +1,32 @@
1
1
  == Cascading Configuration
2
2
 
3
- http://rubygems.org/gems/cascading-configuration-hash
3
+ http://rubygems.org/gems/cascading-configuration
4
4
 
5
- == DESCRIPTION:
6
-
7
- Adds methods for cascading configuration hashes. Support package for cascading-configuration.
5
+ == Description
8
6
 
9
- == SUMMARY:
10
-
11
- * :attr_configuration_hash
7
+ Adds methods for cascading configurations.
12
8
 
13
- == INSTALL:
9
+ == Summary
14
10
 
15
- * sudo gem install cascading-configuration-hash
11
+ Cascading configuration methods for single settings, arrays, hashes.
16
12
 
17
- == EXAMPLE:
13
+ == :attr_configuration_hash
18
14
 
19
- #############################################################################
20
- ######################### attr_configuration_hash ###########################
21
- #############################################################################
15
+ :attr_configuration_hash provides inheritable configuration that cascades downward.
22
16
 
23
- ##################
24
- # first module #
25
- ##################
17
+ Configuration inheritance can cascade through modules, classes, and instances.
26
18
 
27
- module CascadingConfiguration::MockModule
28
- attr_configuration_hash :some_hash_configuration
29
- self.some_hash_configuration = { :some_value => :some_value }
30
- # => some_hash_configuration.should == { :some_value => :some_value }
31
- end
19
+ :attr_configuration_hash defines a single attribute accessor that composes the set of configuration values appropriate to the ancestor level being queried (merging downward from most distant ancestor to self). An internal cache is kept, and any configuration updates that occur to higher-level ancestors cascade immediately downward.
32
20
 
33
- ########################
34
- # including module 1 #
35
- ########################
21
+ == Install
36
22
 
37
- module CascadingConfiguration::MockModule2
38
- # => some_hash_configuration.should == { :some_value => :some_value }
39
- self.some_hash_configuration = { :module_value => :some_value }
40
- # => some_hash_configuration.should == { :module_value => :some_value }
41
- end
23
+ * sudo gem install cascading-configuration
42
24
 
43
- ########################
44
- # including module 2 #
45
- ########################
25
+ == Usage
46
26
 
47
- module CascadingConfiguration::MockModule3
27
+ See supporting package README markdown files (README.md) for examples.
48
28
 
49
- end
50
-
51
- ###############
52
- # top class #
53
- ###############
54
-
55
- class CascadingConfiguration::MockClass
56
- # => some_hash_configuration.should == { :module_value => :some_value }
57
- self.some_hash_configuration = { :another_value => :some_value }
58
- # => some_hash_configuration.should == { :another_value => :some_value }
59
- end
60
-
61
- ###########################
62
- # instance of top class #
63
- ###########################
64
-
65
- object_instance_one = CascadingConfiguration::MockClass.new
66
- # => object_instance_one.some_hash_configuration.should == { :another_value => :some_value }
67
- object_instance_one.some_hash_configuration = { :yet_another_value => :some_value }
68
- # => object_instance_one.some_hash_configuration.should == { :yet_another_value => :some_value }
69
- # => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
70
- # => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
71
-
72
- ############################
73
- # first inheriting class #
74
- ############################
75
-
76
- class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
77
- # => some_hash_configuration.should == { :another_value => :some_value }
78
- self.some_hash_configuration = { :a_value_not_yet_used => :some_value }
79
- # => some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
80
- # => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
81
- # => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
82
- end
83
-
84
- ########################################
85
- # instance of first inheriting class #
86
- ########################################
87
-
88
- object_instance_two = CascadingConfiguration::MockClassSub1.new
89
- # => object_instance_two.some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
90
- # => object_instance_one.some_hash_configuration.should == { :yet_another_value => :some_value }
91
- # => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
92
- # => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
93
-
94
- #############################
95
- # second inheriting class #
96
- #############################
97
-
98
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
99
- # => some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
100
- self.some_hash_configuration = { :another_value_not_yet_used => :some_value }
101
- # => some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
102
- end
103
-
104
- #########################################
105
- # instance of second inheriting class #
106
- #########################################
107
-
108
- object_instance_three = CascadingConfiguration::MockClassSub2.new
109
- # => object_instance_three.some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
110
- object_instance_three.some_hash_configuration = { :one_more_unused_value => :some_value }
111
- # => object_instance_three.some_hash_configuration.should == { :one_more_unused_value => :some_value }
112
-
113
- #############################################################################
114
-
115
- == LICENSE:
29
+ == License
116
30
 
117
31
  (The MIT License)
118
32