cascading-configuration-array 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,347 +1,64 @@
1
1
  # Cascading Configuration #
2
2
 
3
- http://rubygems.org/gems/cascading-configuration-array
3
+ http://rubygems.org/gems/cascading-configuration
4
4
 
5
5
  # Description #
6
6
 
7
- Adds methods for cascading configuration arrays. Support package for cascading-configuration.
7
+ Adds methods for cascading configurations.
8
8
 
9
9
  # Summary #
10
10
 
11
- ## :attr_configuration_array ##
12
-
13
- :attr_configuration_array provides inheritable configuration that cascades downward.
14
-
15
- Configuration inheritance can cascade through modules, classes, and instances.
16
-
17
- :attr_configuration_array 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
- The array maintained by :attr_configuration_array is kept ordered and unique.
20
-
21
- # Install #
22
-
23
- * sudo gem install cascading-configuration-array
24
-
25
- # Usage #
26
-
27
- ## First Module ##
28
-
29
- 1. Define initial configuration in a module.
30
-
31
- A class works just as well, but we can't use a module in the same chain if we start with a class.
32
-
33
- * Include module to enable attr_configuration_array.
34
-
35
- ```ruby
36
-
37
- module CascadingConfiguration::MockModule
38
- include CascadingConfiguration::Array
39
- end
40
-
41
- ```
42
-
43
- * Declare attr_configuration_array.
44
-
45
- ```ruby
46
-
47
- module CascadingConfiguration::MockModule
48
- attr_configuration_array :some_array_configuration
49
- end
50
-
51
- ```
52
-
53
- * Set initial value.
54
-
55
- ```ruby
56
-
57
- module CascadingConfiguration::MockModule
58
- self.some_array_configuration = [ :some_value ]
59
- end
60
-
61
- ```
62
-
63
- * Verify initial configuration value
64
-
65
- ```ruby
66
-
67
- module CascadingConfiguration::MockModule
68
-
69
- # => some_array_configuration.should == [ :some_value ]
70
-
71
- end
72
-
73
- ```
74
-
75
- ## Including Module 1 ##
76
-
77
- 2. Include initial module in another module.
78
-
79
- Including the module that has included a CascadingConfiguration module is the same as including a CascadingConfiguration module.
80
-
81
- ```ruby
82
-
83
- module CascadingConfiguration::MockModule2
84
- include CascadingConfiguration::MockModule
85
- end
86
-
87
- ```
88
-
89
- * Verify inherited value
90
-
91
- ```ruby
92
-
93
- module CascadingConfiguration::MockModule2
94
- # => some_array_configuration.should == [ :some_value ]
95
- end
96
-
97
- ```
98
-
99
- * Override inherited value
100
-
101
- ```ruby
102
-
103
- module CascadingConfiguration::MockModule2
104
- self.some_array_configuration = [ :module_value ]
105
- end
106
-
107
- ```
108
-
109
- * Verify local override value
110
-
111
- ```ruby
112
-
113
- module CascadingConfiguration::MockModule2
114
- # => some_array_configuration.should == [ :module_value ]
115
- end
116
-
117
- ```
118
-
119
- ## Including Module 2 ##
120
-
121
- 3. Include second module in another module.
122
-
123
- ```ruby
124
-
125
- module CascadingConfiguration::MockModule3
126
- include CascadingConfiguration::MockModule2
127
- end
128
-
129
- ```
130
-
131
- * Verify inherited value
132
-
133
- ```ruby
134
-
135
- module CascadingConfiguration::MockModule3
136
- # => some_array_configuration.should == [ :module_value ]
137
- end
138
-
139
- ```
140
-
141
- ## Top Class ##
142
-
143
- 4. Include third module in a class.
144
-
145
- ```ruby
146
-
147
- class CascadingConfiguration::MockClass
148
- include CascadingConfiguration::MockModule3
149
- end
150
-
151
- ```
152
-
153
- * Verify inherited value
154
-
155
- ```ruby
156
-
157
- class CascadingConfiguration::MockClass
158
- # => some_array_configuration.should == [ :module_value ]
159
- end
160
-
161
- ```
162
-
163
- * Override inherited value
11
+ Cascading configuration methods for single settings, arrays, hashes.
164
12
 
165
- ```ruby
166
-
167
- class CascadingConfiguration::MockClass
168
- self.some_array_configuration = [ :another_value ]
169
- end
170
-
171
- ```
172
-
173
- * Verify local override value
174
-
175
- ```ruby
176
-
177
- class CascadingConfiguration::MockClass
178
- # => some_array_configuration.should == [ :another_value ]
179
- end
180
-
181
- ```
182
-
183
- ## Instance of Top Class ##
184
-
185
- 5. Instantiate class.
186
-
187
- ```ruby
188
-
189
- object_instance_one = CascadingConfiguration::MockClass.new
190
-
191
- ```
192
-
193
- * Verify inherited value
194
-
195
- ```ruby
196
-
197
- # => object_instance_one.some_array_configuration.should == [ :another_value ]
198
-
199
- ```
200
-
201
- * Override inherited value
202
-
203
- ```ruby
204
-
205
- object_instance_one.some_array_configuration = [ :yet_another_value ]
206
-
207
- ```
208
-
209
- * Verify local override value
210
-
211
- ```ruby
212
-
213
- # => object_instance_one.some_array_configuration.should == [ :yet_another_value ]
214
- # => CascadingConfiguration::MockClass.some_array_configuration.should == [ :another_value ]
215
- # => CascadingConfiguration::MockModule.some_array_configuration.should == [ :some_value ]
216
-
217
- ```
218
-
219
- # First Inheriting Class #
220
-
221
- 6. Inheriting class.
222
-
223
- Inheriting class should not get any settings from instance of superclass.
224
-
225
- * Verify inherited value
226
-
227
- ```ruby
228
-
229
- class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
230
- # => some_array_configuration.should == [ :another_value ]
231
- end
232
-
233
- ```
234
-
235
- * Override inherited value
236
-
237
- ```ruby
238
-
239
- class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
240
- self.some_array_configuration = [ :a_value_not_yet_used ]
241
- end
242
-
243
- ```
13
+ ## :attr_configuration ##
244
14
 
245
- * Verify local override value
15
+ :attr_configuration provides inheritable configuration that cascades downward.
246
16
 
247
- ```ruby
248
-
249
- class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
250
- # => some_array_configuration.should == [ :a_value_not_yet_used ]
251
- # => CascadingConfiguration::MockClass.some_array_configuration.should == [ :another_value ]
252
- # => CascadingConfiguration::MockModule.some_array_configuration.should == [ :some_value ]
253
- end
254
-
255
- ```
256
-
257
- ## Instance of First Inheriting Class ##
258
-
259
- 7. Instantiate first inheriting class.
260
-
261
- ```ruby
262
-
263
- object_instance_two = CascadingConfiguration::MockClassSub1.new
264
-
265
- ```
17
+ Configuration inheritance can cascade through modules, classes, and instances.
266
18
 
267
- * Verify inherited value
19
+ :attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
268
20
 
269
- ```ruby
21
+ ## :attr_configuration_array ##
270
22
 
271
- # => object_instance_two.some_array_configuration.should == [ :a_value_not_yet_used ]
272
- # => object_instance_one.some_array_configuration.should == [ :yet_another_value ]
273
- # => CascadingConfiguration::MockClass.some_array_configuration.should == [ :another_value ]
274
- # => CascadingConfiguration::MockModule.some_array_configuration.should == [ :some_value ]
23
+ :attr_configuration_array provides inheritable configuration that cascades downward.
275
24
 
276
- ```
25
+ Configuration inheritance can cascade through modules, classes, and instances.
277
26
 
278
- ## Second Inheriting Class ##
27
+ :attr_configuration_array 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.
279
28
 
280
- 8. Second inheriting class.
29
+ The array maintained by :attr_configuration_array is kept ordered and unique.
281
30
 
282
- * Verify inherited value
31
+ ## :attr_configuration_hash ##
283
32
 
284
- ```ruby
33
+ :attr_configuration_hash provides inheritable configuration that cascades downward.
285
34
 
286
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
287
- # => some_array_configuration.should == [ :a_value_not_yet_used ]
288
- end
35
+ Configuration inheritance can cascade through modules, classes, and instances.
289
36
 
290
- ```
37
+ :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.
291
38
 
292
- * Override inherited value
39
+ # Install #
293
40
 
294
- ```ruby
41
+ * sudo gem install cascading-configuration
295
42
 
296
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
297
- self.some_array_configuration = [ :another_value_not_yet_used ]
298
- end
43
+ # Usage #
299
44
 
300
- ```
45
+ Including CascadingConfiguration includes:
301
46
 
302
- * Verify local override value
47
+ * CascadingConfiguration::Setting
48
+ * CascadingConfiguration::Array
49
+ * CascadingConfiguration::Hash
303
50
 
304
51
  ```ruby
305
-
306
- class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
307
- # => some_array_configuration.should == [ :another_value_not_yet_used ]
52
+ module AnyModuleOrClass
53
+ include CascadingConfiguration
308
54
  end
309
-
310
- ```
311
-
312
- ## Instance of Second Inheriting Class ##
313
-
314
- 9. Instantiate Second Inheriting Class.
315
-
316
- ```ruby
317
-
318
- object_instance_three = CascadingConfiguration::MockClassSub2.new
319
-
320
55
  ```
321
56
 
322
- * Verify inherited value
323
-
324
- ```ruby
325
-
326
- # => object_instance_three.some_array_configuration.should == [ :another_value_not_yet_used ]
57
+ See supporting package README files for examples in each case:
327
58
 
328
- ```
329
-
330
- * Override inherited value
331
-
332
- ```ruby
333
-
334
- object_instance_three.some_array_configuration = [ :one_more_unused_value ]
335
-
336
- ```
337
-
338
- * Verify local override value
339
-
340
- ```ruby
341
-
342
- # => object_instance_three.some_array_configuration.should == [ :one_more_unused_value ]
343
-
344
- ```
59
+ * attr_configuration
60
+ * attr_configuration_array
61
+ * attr_configuration_hash
345
62
 
346
63
  # License #
347
64
 
data/README.rdoc CHANGED
@@ -10,6 +10,14 @@ Adds methods for cascading configurations.
10
10
 
11
11
  Cascading configuration methods for single settings, arrays, hashes.
12
12
 
13
+ == :attr_configuration
14
+
15
+ :attr_configuration provides inheritable configuration that cascades downward.
16
+
17
+ Configuration inheritance can cascade through modules, classes, and instances.
18
+
19
+ :attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
20
+
13
21
  == :attr_configuration_array
14
22
 
15
23
  :attr_configuration_array provides inheritable configuration that cascades downward.
@@ -20,13 +28,29 @@ Configuration inheritance can cascade through modules, classes, and instances.
20
28
 
21
29
  The array maintained by :attr_configuration_array is kept ordered and unique.
22
30
 
31
+ == :attr_configuration_hash
32
+
33
+ :attr_configuration_hash provides inheritable configuration that cascades downward.
34
+
35
+ Configuration inheritance can cascade through modules, classes, and instances.
36
+
37
+ :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.
38
+
23
39
  == Install
24
40
 
25
41
  * sudo gem install cascading-configuration
26
42
 
27
43
  == Usage
28
44
 
29
- See supporting package README markdown files (README.md) for examples.
45
+ module AnyModuleOrClass
46
+ include CascadingConfiguration
47
+ end
48
+
49
+ For further details, see supporting package README markdown files (README.md) for examples in each case:
50
+
51
+ * attr_configuration
52
+ * attr_configuration_array
53
+ * attr_configuration_hash
30
54
 
31
55
  == License
32
56
 
@@ -0,0 +1,16 @@
1
+
2
+ module CascadingConfiguration
3
+
4
+ ###################
5
+ # self.included #
6
+ ###################
7
+
8
+ def self.included( class_or_module )
9
+ class_or_module.instance_eval do
10
+ include CascadingConfiguration::Setting
11
+ include CascadingConfiguration::Array
12
+ include CascadingConfiguration::Hash
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,15 @@
1
+
2
+ if $cascading_configuration_development
3
+ require_relative '../setting/lib/cascading-configuration-setting.rb'
4
+ require_relative '../settings-array/lib/cascading-configuration-array.rb'
5
+ require_relative '../settings-hash/lib/cascading-configuration-hash.rb'
6
+ else
7
+ require 'cascading-configuration-setting'
8
+ require 'cascading-configuration-array'
9
+ require 'cascading-configuration-hash'
10
+ end
11
+
12
+ module CascadingConfiguration
13
+ end
14
+
15
+ require_relative 'cascading-configuration/CascadingConfiguration.rb'
@@ -0,0 +1,224 @@
1
+
2
+ require_relative '../lib/cascading-configuration.rb'
3
+
4
+ describe CascadingConfiguration do
5
+
6
+ ########################
7
+ # attr_configuration #
8
+ ########################
9
+
10
+ it 'can declare an attribute as a cascading configuration setting' do
11
+ module CascadingConfiguration::MockModule2
12
+ end
13
+
14
+ # first module
15
+ module CascadingConfiguration::MockModule
16
+ include CascadingConfiguration
17
+ attr_configuration :some_configuration
18
+ self.some_configuration = :some_value
19
+ some_configuration.should == :some_value
20
+ end
21
+
22
+ # including module 1
23
+ module CascadingConfiguration::MockModule2
24
+ include CascadingConfiguration::MockModule
25
+ some_configuration.should == :some_value
26
+ self.some_configuration = :module_value
27
+ some_configuration.should == :module_value
28
+ end
29
+
30
+ # including module 2
31
+ module CascadingConfiguration::MockModule3
32
+ include CascadingConfiguration::MockModule2
33
+ end
34
+
35
+ # top class
36
+ class CascadingConfiguration::MockClass
37
+ include CascadingConfiguration::MockModule3
38
+ some_configuration.should == :module_value
39
+ self.some_configuration = :another_value
40
+ some_configuration.should == :another_value
41
+ end
42
+
43
+ # instance of top class
44
+ object_instance_one = CascadingConfiguration::MockClass.new
45
+ object_instance_one.some_configuration.should == :another_value
46
+ object_instance_one.some_configuration = :yet_another_value
47
+ object_instance_one.some_configuration.should == :yet_another_value
48
+ CascadingConfiguration::MockClass.some_configuration.should == :another_value
49
+ CascadingConfiguration::MockModule.some_configuration.should == :some_value
50
+
51
+ # first inheriting class
52
+ class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
53
+ some_configuration.should == :another_value
54
+ self.some_configuration = :a_value_not_yet_used
55
+ some_configuration.should == :a_value_not_yet_used
56
+ CascadingConfiguration::MockClass.some_configuration.should == :another_value
57
+ CascadingConfiguration::MockModule.some_configuration.should == :some_value
58
+ end
59
+
60
+ # Instance of First Inheriting Class
61
+ object_instance_two = CascadingConfiguration::MockClassSub1.new
62
+ object_instance_two.some_configuration.should == :a_value_not_yet_used
63
+ object_instance_one.some_configuration.should == :yet_another_value
64
+ CascadingConfiguration::MockClass.some_configuration.should == :another_value
65
+ CascadingConfiguration::MockModule.some_configuration.should == :some_value
66
+
67
+ # Second Inheriting Class
68
+ class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
69
+ some_configuration.should == :a_value_not_yet_used
70
+ self.some_configuration = :another_value_not_yet_used
71
+ some_configuration.should == :another_value_not_yet_used
72
+ end
73
+
74
+ # Instance of Second Inheriting Class
75
+ object_instance_three = CascadingConfiguration::MockClassSub2.new
76
+ object_instance_three.some_configuration.should == :another_value_not_yet_used
77
+ object_instance_three.some_configuration = :one_more_unused_value
78
+ object_instance_three.some_configuration.should == :one_more_unused_value
79
+
80
+ end
81
+
82
+ ##############################
83
+ # attr_configuration_array #
84
+ ##############################
85
+
86
+ it 'can declare an attribute as a cascading configuration array' do
87
+
88
+ # first module
89
+ module CascadingConfiguration::MockModule
90
+ attr_configuration_array :some_array_configuration
91
+ self.some_array_configuration = [ :some_value ]
92
+ some_array_configuration.should == [ :some_value ]
93
+ end
94
+
95
+ # including module 1
96
+ module CascadingConfiguration::MockModule2
97
+ some_array_configuration.should == [ :some_value ]
98
+ self.some_array_configuration = [ :module_value ]
99
+ some_array_configuration.should == [ :module_value ]
100
+ end
101
+
102
+ # including module 2
103
+ module CascadingConfiguration::MockModule3
104
+ some_array_configuration.should == [ :module_value ]
105
+ end
106
+
107
+ # top class
108
+ class CascadingConfiguration::MockClass
109
+ some_array_configuration.should == [ :module_value ]
110
+ self.some_array_configuration = [ :another_value ]
111
+ some_array_configuration.should == [ :another_value ]
112
+ end
113
+
114
+ # instance of top class
115
+ object_instance_one = CascadingConfiguration::MockClass.new
116
+ object_instance_one.some_array_configuration.should == [ :another_value ]
117
+ object_instance_one.some_array_configuration = [ :yet_another_value ]
118
+ object_instance_one.some_array_configuration.should == [ :yet_another_value ]
119
+ CascadingConfiguration::MockClass.some_array_configuration.should == [ :another_value ]
120
+ CascadingConfiguration::MockModule.some_array_configuration.should == [ :some_value ]
121
+
122
+ # first inheriting class
123
+ class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
124
+ some_array_configuration.should == [ :another_value ]
125
+ self.some_array_configuration = [ :a_value_not_yet_used ]
126
+ some_array_configuration.should == [ :a_value_not_yet_used ]
127
+ CascadingConfiguration::MockClass.some_array_configuration.should == [ :another_value ]
128
+ CascadingConfiguration::MockModule.some_array_configuration.should == [ :some_value ]
129
+ end
130
+
131
+ # Instance of First Inheriting Class
132
+ object_instance_two = CascadingConfiguration::MockClassSub1.new
133
+ object_instance_two.some_array_configuration.should == [ :a_value_not_yet_used ]
134
+ object_instance_one.some_array_configuration.should == [ :yet_another_value ]
135
+ CascadingConfiguration::MockClass.some_array_configuration.should == [ :another_value ]
136
+ CascadingConfiguration::MockModule.some_array_configuration.should == [ :some_value ]
137
+
138
+ # Second Inheriting Class
139
+ class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
140
+ some_array_configuration.should == [ :a_value_not_yet_used ]
141
+ self.some_array_configuration = [ :another_value_not_yet_used ]
142
+ some_array_configuration.should == [ :another_value_not_yet_used ]
143
+ end
144
+
145
+ # Instance of Second Inheriting Class
146
+ object_instance_three = CascadingConfiguration::MockClassSub2.new
147
+ object_instance_three.some_array_configuration.should == [ :another_value_not_yet_used ]
148
+ object_instance_three.some_array_configuration = [ :one_more_unused_value ]
149
+ object_instance_three.some_array_configuration.should == [ :one_more_unused_value ]
150
+
151
+ end
152
+
153
+ #############################
154
+ # attr_configuration_hash #
155
+ #############################
156
+
157
+ it 'can declare an attribute as a cascading configuration hash' do
158
+
159
+ # first module
160
+ module CascadingConfiguration::MockModule
161
+ attr_configuration_hash :some_hash_configuration
162
+ self.some_hash_configuration = { :some_value => :some_value }
163
+ some_hash_configuration.should == { :some_value => :some_value }
164
+ end
165
+
166
+ # including module 1
167
+ module CascadingConfiguration::MockModule2
168
+ some_hash_configuration.should == { :some_value => :some_value }
169
+ self.some_hash_configuration = { :module_value => :some_value }
170
+ some_hash_configuration.should == { :module_value => :some_value }
171
+ end
172
+
173
+ # including module 2
174
+ module CascadingConfiguration::MockModule3
175
+
176
+ end
177
+
178
+ # top class
179
+ class CascadingConfiguration::MockClass
180
+ some_hash_configuration.should == { :module_value => :some_value }
181
+ self.some_hash_configuration = { :another_value => :some_value }
182
+ some_hash_configuration.should == { :another_value => :some_value }
183
+ end
184
+
185
+ # instance of top class
186
+ object_instance_one = CascadingConfiguration::MockClass.new
187
+ object_instance_one.some_hash_configuration.should == { :another_value => :some_value }
188
+ object_instance_one.some_hash_configuration = { :yet_another_value => :some_value }
189
+ object_instance_one.some_hash_configuration.should == { :yet_another_value => :some_value }
190
+ CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
191
+ CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
192
+
193
+ # first inheriting class
194
+ class CascadingConfiguration::MockClassSub1 < CascadingConfiguration::MockClass
195
+ some_hash_configuration.should == { :another_value => :some_value }
196
+ self.some_hash_configuration = { :a_value_not_yet_used => :some_value }
197
+ some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
198
+ CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
199
+ CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
200
+ end
201
+
202
+ # Instance of First Inheriting Class
203
+ object_instance_two = CascadingConfiguration::MockClassSub1.new
204
+ object_instance_two.some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
205
+ object_instance_one.some_hash_configuration.should == { :yet_another_value => :some_value }
206
+ CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
207
+ CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
208
+
209
+ # Second Inheriting Class
210
+ class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
211
+ some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
212
+ self.some_hash_configuration = { :another_value_not_yet_used => :some_value }
213
+ some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
214
+ end
215
+
216
+ # Instance of Second Inheriting Class
217
+ object_instance_three = CascadingConfiguration::MockClassSub2.new
218
+ object_instance_three.some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
219
+ object_instance_three.some_hash_configuration = { :one_more_unused_value => :some_value }
220
+ object_instance_three.some_hash_configuration.should == { :one_more_unused_value => :some_value }
221
+
222
+ end
223
+
224
+ end