cascading-configuration-hash 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 +29 -308
- data/README.rdoc +27 -1
- data/lib/cascading-configuration/CascadingConfiguration.rb +16 -0
- data/lib/cascading-configuration.rb +15 -0
- data/spec/CascadingConfiguration_spec.rb +224 -0
- metadata +5 -16
- data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb +0 -39
- data/lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb +0 -136
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Accessors.rb +0 -33
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/ClassInstance.rb +0 -24
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInstance.rb +0 -36
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb +0 -24
- data/lib/cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb +0 -83
- data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/CompositingHash.rb +0 -79
- data/lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb +0 -31
- data/lib/cascading-configuration-hash.rb +0 -35
- data/spec/CascadingConfiguration/CascadingCompositeHash_spec.rb +0 -402
- data/spec/CascadingConfiguration/ConfigurationHash_spec.rb +0 -95
- data/spec/CascadingConfiguration/Hash/Accessors_spec.rb +0 -28
- data/spec/CascadingConfiguration/Hash_spec.rb +0 -144
data/README.md
CHANGED
@@ -1,343 +1,64 @@
|
|
1
1
|
# Cascading Configuration #
|
2
2
|
|
3
|
-
http://rubygems.org/gems/cascading-configuration
|
3
|
+
http://rubygems.org/gems/cascading-configuration
|
4
4
|
|
5
5
|
# Description #
|
6
6
|
|
7
|
-
Adds methods for cascading
|
7
|
+
Adds methods for cascading configurations.
|
8
8
|
|
9
9
|
# Summary #
|
10
10
|
|
11
|
-
|
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
|
11
|
+
Cascading configuration methods for single settings, arrays, hashes.
|
86
12
|
|
87
|
-
|
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
|
-
```
|
13
|
+
## :attr_configuration ##
|
126
14
|
|
127
|
-
|
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
|
15
|
+
:attr_configuration provides inheritable configuration that cascades downward.
|
166
16
|
|
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
|
-
```
|
17
|
+
Configuration inheritance can cascade through modules, classes, and instances.
|
262
18
|
|
263
|
-
|
19
|
+
:attr_configuration defines a single attribute accessor that searches upward for the first ancestor defining the configuration.
|
264
20
|
|
265
|
-
|
21
|
+
## :attr_configuration_array ##
|
266
22
|
|
267
|
-
|
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 }
|
23
|
+
:attr_configuration_array provides inheritable configuration that cascades downward.
|
271
24
|
|
272
|
-
|
25
|
+
Configuration inheritance can cascade through modules, classes, and instances.
|
273
26
|
|
274
|
-
|
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.
|
275
28
|
|
276
|
-
|
29
|
+
The array maintained by :attr_configuration_array is kept ordered and unique.
|
277
30
|
|
278
|
-
|
31
|
+
## :attr_configuration_hash ##
|
279
32
|
|
280
|
-
|
33
|
+
:attr_configuration_hash provides inheritable configuration that cascades downward.
|
281
34
|
|
282
|
-
|
283
|
-
# => some_hash_configuration.should == { :a_value_not_yet_used => :some_value }
|
284
|
-
end
|
35
|
+
Configuration inheritance can cascade through modules, classes, and instances.
|
285
36
|
|
286
|
-
|
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.
|
287
38
|
|
288
|
-
|
39
|
+
# Install #
|
289
40
|
|
290
|
-
|
41
|
+
* sudo gem install cascading-configuration
|
291
42
|
|
292
|
-
|
293
|
-
self.some_hash_configuration = { :another_value_not_yet_used => :some_value }
|
294
|
-
end
|
43
|
+
# Usage #
|
295
44
|
|
296
|
-
|
45
|
+
Including CascadingConfiguration includes:
|
297
46
|
|
298
|
-
*
|
47
|
+
* CascadingConfiguration::Setting
|
48
|
+
* CascadingConfiguration::Array
|
49
|
+
* CascadingConfiguration::Hash
|
299
50
|
|
300
51
|
```ruby
|
301
|
-
|
302
|
-
|
303
|
-
# => some_hash_configuration.should == { :another_value_not_yet_used => :some_value }
|
52
|
+
module AnyModuleOrClass
|
53
|
+
include CascadingConfiguration
|
304
54
|
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
55
|
```
|
325
56
|
|
326
|
-
|
57
|
+
See supporting package README files for examples in each case:
|
327
58
|
|
328
|
-
|
329
|
-
|
330
|
-
|
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
|
-
```
|
59
|
+
* attr_configuration
|
60
|
+
* attr_configuration_array
|
61
|
+
* attr_configuration_hash
|
341
62
|
|
342
63
|
# License #
|
343
64
|
|
data/README.rdoc
CHANGED
@@ -10,6 +10,24 @@ 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
|
+
== :attr_configuration_array
|
22
|
+
|
23
|
+
:attr_configuration_array provides inheritable configuration that cascades downward.
|
24
|
+
|
25
|
+
Configuration inheritance can cascade through modules, classes, and instances.
|
26
|
+
|
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.
|
28
|
+
|
29
|
+
The array maintained by :attr_configuration_array is kept ordered and unique.
|
30
|
+
|
13
31
|
== :attr_configuration_hash
|
14
32
|
|
15
33
|
:attr_configuration_hash provides inheritable configuration that cascades downward.
|
@@ -24,7 +42,15 @@ Configuration inheritance can cascade through modules, classes, and instances.
|
|
24
42
|
|
25
43
|
== Usage
|
26
44
|
|
27
|
-
|
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
|
28
54
|
|
29
55
|
== License
|
30
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
|