cascading-configuration-array 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +312 -29
- data/README.rdoc +1 -25
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/Accessors.rb +38 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/ClassInstance.rb +19 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/Array/ModuleInstance.rb +34 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/Array.rb +24 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/CompositingArray/Instance.rb +39 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/CompositingArray.rb +216 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/LocalConfigurationArray.rb +166 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/_private_/CompositingArray.rb +57 -0
- data/lib/cascading-configuration-array/CascadingConfiguration/_private_/LocalConfigurationArray.rb +26 -0
- data/lib/cascading-configuration-array.rb +35 -0
- data/spec/CascadingConfiguration/Array/Accessors_spec.rb +28 -0
- data/spec/CascadingConfiguration/Array_spec.rb +90 -0
- data/spec/CascadingConfiguration/CompositingArray_spec.rb +519 -0
- data/spec/CascadingConfiguration/LocalConfigurationArray_spec.rb +155 -0
- metadata +16 -5
- data/lib/cascading-configuration/CascadingConfiguration.rb +0 -16
- data/lib/cascading-configuration.rb +0 -15
- data/spec/CascadingConfiguration_spec.rb +0 -224
data/README.md
CHANGED
@@ -1,23 +1,13 @@
|
|
1
1
|
# Cascading Configuration #
|
2
2
|
|
3
|
-
http://rubygems.org/gems/cascading-configuration
|
3
|
+
http://rubygems.org/gems/cascading-configuration-array
|
4
4
|
|
5
5
|
# Description #
|
6
6
|
|
7
|
-
Adds methods for cascading
|
7
|
+
Adds methods for cascading configuration arrays. Support package for cascading-configuration.
|
8
8
|
|
9
9
|
# Summary #
|
10
10
|
|
11
|
-
Cascading configuration methods for single settings, arrays, hashes.
|
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
|
-
|
21
11
|
## :attr_configuration_array ##
|
22
12
|
|
23
13
|
:attr_configuration_array provides inheritable configuration that cascades downward.
|
@@ -28,37 +18,330 @@ Configuration inheritance can cascade through modules, classes, and instances.
|
|
28
18
|
|
29
19
|
The array maintained by :attr_configuration_array is kept ordered and unique.
|
30
20
|
|
31
|
-
|
21
|
+
# Install #
|
22
|
+
|
23
|
+
* sudo gem install cascading-configuration-array
|
32
24
|
|
33
|
-
|
25
|
+
# Usage #
|
34
26
|
|
35
|
-
|
27
|
+
## First Module ##
|
36
28
|
|
37
|
-
|
29
|
+
1. Define initial configuration in a module.
|
38
30
|
|
39
|
-
|
31
|
+
A class works just as well, but we can't use a module in the same chain if we start with a class.
|
40
32
|
|
41
|
-
*
|
33
|
+
* Include module to enable attr_configuration_array.
|
42
34
|
|
43
|
-
|
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
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
|
167
|
+
class CascadingConfiguration::MockClass
|
168
|
+
self.some_array_configuration = [ :another_value ]
|
169
|
+
end
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
* Verify local override value
|
44
174
|
|
45
|
-
|
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
|
+
```
|
244
|
+
|
245
|
+
* Verify local override value
|
246
|
+
|
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
|
+
```
|
46
256
|
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
+
```
|
266
|
+
|
267
|
+
* Verify inherited value
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
|
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 ]
|
275
|
+
|
276
|
+
```
|
277
|
+
|
278
|
+
## Second Inheriting Class ##
|
279
|
+
|
280
|
+
8. Second inheriting class.
|
281
|
+
|
282
|
+
* Verify inherited value
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
|
286
|
+
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
287
|
+
# => some_array_configuration.should == [ :a_value_not_yet_used ]
|
288
|
+
end
|
289
|
+
|
290
|
+
```
|
291
|
+
|
292
|
+
* Override inherited value
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
|
296
|
+
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
297
|
+
self.some_array_configuration = [ :another_value_not_yet_used ]
|
298
|
+
end
|
299
|
+
|
300
|
+
```
|
301
|
+
|
302
|
+
* Verify local override value
|
50
303
|
|
51
304
|
```ruby
|
52
|
-
|
53
|
-
|
305
|
+
|
306
|
+
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
307
|
+
# => some_array_configuration.should == [ :another_value_not_yet_used ]
|
54
308
|
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
|
+
|
55
320
|
```
|
56
321
|
|
57
|
-
|
322
|
+
* Verify inherited value
|
323
|
+
|
324
|
+
```ruby
|
325
|
+
|
326
|
+
# => object_instance_three.some_array_configuration.should == [ :another_value_not_yet_used ]
|
58
327
|
|
59
|
-
|
60
|
-
|
61
|
-
*
|
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
|
+
```
|
62
345
|
|
63
346
|
# License #
|
64
347
|
|
data/README.rdoc
CHANGED
@@ -10,14 +10,6 @@ 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
|
-
|
21
13
|
== :attr_configuration_array
|
22
14
|
|
23
15
|
:attr_configuration_array provides inheritable configuration that cascades downward.
|
@@ -28,29 +20,13 @@ Configuration inheritance can cascade through modules, classes, and instances.
|
|
28
20
|
|
29
21
|
The array maintained by :attr_configuration_array is kept ordered and unique.
|
30
22
|
|
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
|
-
|
39
23
|
== Install
|
40
24
|
|
41
25
|
* sudo gem install cascading-configuration
|
42
26
|
|
43
27
|
== Usage
|
44
28
|
|
45
|
-
|
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
|
29
|
+
See supporting package README markdown files (README.md) for examples.
|
54
30
|
|
55
31
|
== License
|
56
32
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Array::Accessors
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
###################################
|
7
|
+
# define_cascading_array_setter #
|
8
|
+
###################################
|
9
|
+
|
10
|
+
def define_cascading_array_setter( configuration_name )
|
11
|
+
configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
|
12
|
+
self::AccessorSupportModule.module_eval do
|
13
|
+
define_method( configuration_setter_name ) do |array|
|
14
|
+
composite_array = composite_array_for_cascading_configuration( configuration_name )
|
15
|
+
# we want the array to supplant existing config
|
16
|
+
# clear the array (excludes everything explicitly)
|
17
|
+
composite_array.clear
|
18
|
+
# push array elements (removes anything excluded from exclude)
|
19
|
+
composite_array.push( *array )
|
20
|
+
return composite_array
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
###################################
|
26
|
+
# define_cascading_array_getter #
|
27
|
+
###################################
|
28
|
+
|
29
|
+
def define_cascading_array_getter( configuration_name )
|
30
|
+
configuration_getter_name = configuration_name
|
31
|
+
self::AccessorSupportModule.module_eval do
|
32
|
+
define_method( configuration_getter_name ) do
|
33
|
+
return composite_array_for_cascading_configuration( configuration_name )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Array::ClassInstance
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
##############################
|
7
|
+
# attr_configuration_array #
|
8
|
+
##############################
|
9
|
+
|
10
|
+
def attr_configuration_array( *property_names )
|
11
|
+
property_names.each do |this_property_name|
|
12
|
+
# define configuration setter
|
13
|
+
define_cascading_array_setter( this_property_name )
|
14
|
+
# define configuration getter
|
15
|
+
define_cascading_array_getter( this_property_name )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Array::ModuleInstance
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
##############
|
7
|
+
# included #
|
8
|
+
##############
|
9
|
+
|
10
|
+
def included( class_or_module )
|
11
|
+
super if method_defined?( :super )
|
12
|
+
# CascadingConfiguration::Array
|
13
|
+
module_self = self
|
14
|
+
class_or_module.instance_eval do
|
15
|
+
# cascade CascadingConfiguration::Array
|
16
|
+
include CascadingConfiguration::Array
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
##############
|
21
|
+
# extended #
|
22
|
+
##############
|
23
|
+
|
24
|
+
def extended( class_or_module )
|
25
|
+
super if method_defined?( :super )
|
26
|
+
# CascadingConfiguration::Array
|
27
|
+
module_self = self
|
28
|
+
class_or_module.instance_eval do
|
29
|
+
# cascade CascadingConfiguration::Array
|
30
|
+
include CascadingConfiguration::Array
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::Array
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
include CascadingConfiguration::Variable
|
7
|
+
include CascadingConfiguration::CompositingArray::Instance
|
8
|
+
|
9
|
+
###################
|
10
|
+
# self.included #
|
11
|
+
###################
|
12
|
+
|
13
|
+
def self.included( class_or_module )
|
14
|
+
module_self = self
|
15
|
+
class_or_module.instance_eval do
|
16
|
+
extend module_self
|
17
|
+
extend module_self::Accessors
|
18
|
+
extend module_self::ClassInstance
|
19
|
+
# module support
|
20
|
+
extend CascadingConfiguration::Array::ModuleInstance unless is_a?( Class )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
module CascadingConfiguration::CompositingArray::Instance
|
3
|
+
|
4
|
+
extend CascadingConfiguration::InternalModuleStub
|
5
|
+
|
6
|
+
###################
|
7
|
+
# self.included #
|
8
|
+
###################
|
9
|
+
|
10
|
+
def self.included( class_or_module )
|
11
|
+
module_self = self
|
12
|
+
class_or_module.instance_eval do
|
13
|
+
extend module_self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#################################################
|
18
|
+
# composite_array_for_cascading_configuration #
|
19
|
+
#################################################
|
20
|
+
|
21
|
+
def composite_array_for_cascading_configuration( cascading_name )
|
22
|
+
|
23
|
+
composite_array = nil
|
24
|
+
|
25
|
+
klass = ( is_a?( Module ) ? self : self.class )
|
26
|
+
accessor_support_module = klass::AccessorSupportModule
|
27
|
+
self_instance = self
|
28
|
+
accessor_support_module.instance_eval do
|
29
|
+
unless composite_array = ( ( @composite_arrays ||= Hash.new )[ cascading_name ] ||= Hash.new )[ self_instance ]
|
30
|
+
composite_array = ::CascadingConfiguration::CompositingArray.new( cascading_name, self_instance )
|
31
|
+
@composite_arrays[ cascading_name ][ self_instance ] = composite_array
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
return composite_array
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|