cascading-configuration-hash 1.1.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +118 -200
- data/README.rdoc +12 -8
- data/lib/cascading-configuration-hash.rb +2 -2
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb +2 -2
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/{ConfigurationAccessors.rb → AccessorDefinitionMethods.rb} +7 -7
- data/lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb +8 -5
- data/spec/CascadingConfiguration/Hash/{ConfigurationAccessors_spec.rb → AccessorDefinitionMethods_spec.rb} +2 -2
- data/spec/CascadingConfiguration/Hash_spec.rb +336 -26
- metadata +5 -5
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Cascading Configuration #
|
1
|
+
# Cascading Configuration Hash #
|
2
2
|
|
3
3
|
http://rubygems.org/gems/cascading-configuration-hash
|
4
4
|
|
@@ -8,336 +8,254 @@ Adds methods for cascading configuration hashes. Support package for cascading-c
|
|
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.
|
11
|
+
Cascading configuration methods for hashes, which returns the appropriate lowest accumulated value. Configuration inheritance can cascade through modules, classes, and to instances.
|
16
12
|
|
17
|
-
|
13
|
+
This means that we can create configuration modules, optionally setting configuration defaults, and include those configuration modules in other modules or classes.
|
18
14
|
|
19
15
|
# Install #
|
20
16
|
|
21
|
-
* sudo gem install cascading-configuration
|
17
|
+
* sudo gem install cascading-configuration
|
22
18
|
|
23
19
|
# Usage #
|
24
20
|
|
25
|
-
|
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.
|
21
|
+
Including the module will enable support for singleton and for instances.
|
42
22
|
|
43
23
|
```ruby
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
24
|
+
module AnyModuleOrClass
|
25
|
+
include CascadingConfiguration
|
26
|
+
end
|
49
27
|
```
|
50
28
|
|
51
|
-
|
29
|
+
Extending the module will enable support for singleton only.
|
52
30
|
|
53
31
|
```ruby
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
32
|
+
module AnyModuleOrClass
|
33
|
+
extend CascadingConfiguration
|
34
|
+
end
|
59
35
|
```
|
60
36
|
|
61
|
-
|
62
|
-
|
63
|
-
```ruby
|
37
|
+
Including or extending CascadingConfiguration includes or extends:
|
64
38
|
|
65
|
-
|
66
|
-
# => some_hash_configuration.should == { :some_value => :some_value }
|
67
|
-
end
|
39
|
+
* CascadingConfiguration::Variable
|
68
40
|
|
69
|
-
|
41
|
+
## :attr_configuration_hash ##
|
70
42
|
|
71
|
-
|
43
|
+
:attr_configuration_array provides inheritable hash configurations that cascade downward. A composite hash will be returned (merging downward from most distant ancestor to self).
|
72
44
|
|
73
|
-
|
45
|
+
An internal cache is kept, and any configuration updates that occur to higher-level ancestors cascade immediately downward.
|
74
46
|
|
75
|
-
|
47
|
+
Define initial configuration in a module or class:
|
76
48
|
|
77
49
|
```ruby
|
50
|
+
module SomeModule
|
78
51
|
|
79
|
-
|
80
|
-
include CascadingConfiguration::MockModule
|
81
|
-
end
|
52
|
+
include CascadingConfiguration::Hash
|
82
53
|
|
83
|
-
|
54
|
+
attr_configuration_hash :some_hash_setting
|
84
55
|
|
85
|
-
|
56
|
+
some_hash_setting # => nil
|
86
57
|
|
87
|
-
|
58
|
+
some_hash_setting[ :some_setting ] = :some_value
|
88
59
|
|
89
|
-
|
90
|
-
# => some_hash_configuration.should == { :some_value => :some_value }
|
91
|
-
end
|
60
|
+
some_hash_setting[ :some_setting ] # => :some_value
|
92
61
|
|
62
|
+
end
|
93
63
|
```
|
94
64
|
|
95
|
-
|
65
|
+
Include initial module in a module or class:
|
96
66
|
|
97
67
|
```ruby
|
68
|
+
class SomeClass
|
98
69
|
|
99
|
-
|
100
|
-
self.some_hash_configuration = { :module_value => :some_value }
|
101
|
-
end
|
102
|
-
|
103
|
-
```
|
70
|
+
include SomeModule
|
104
71
|
|
105
|
-
|
72
|
+
some_hash_setting[ :some_setting ] # => :some_value
|
106
73
|
|
107
|
-
|
74
|
+
self.some_hash_setting.replace( :some_other_setting => :some_other_value )
|
108
75
|
|
109
|
-
|
110
|
-
# => some_hash_configuration.should == { :module_value => :some_value }
|
111
|
-
end
|
76
|
+
some_hash_setting # => { :some_other_setting => :some_other_value }
|
112
77
|
|
78
|
+
end
|
113
79
|
```
|
114
80
|
|
115
|
-
|
116
|
-
|
117
|
-
3. Include second module in another module.
|
81
|
+
And it cascades to instances:
|
118
82
|
|
119
83
|
```ruby
|
84
|
+
instance = SomeClass.new
|
120
85
|
|
121
|
-
|
122
|
-
include CascadingConfiguration::MockModule2
|
123
|
-
end
|
124
|
-
|
125
|
-
```
|
126
|
-
|
127
|
-
* Verify inherited value
|
128
|
-
|
129
|
-
```ruby
|
86
|
+
instance.some_hash_setting.should == { :some_other_setting => :some_other_value }
|
130
87
|
|
131
|
-
|
132
|
-
# => some_array_configuration.should == { :module_value => :some_value }
|
133
|
-
end
|
88
|
+
instance.some_hash_setting.delete( :some_other_setting )
|
134
89
|
|
90
|
+
instance.some_hash_setting.should == {}
|
135
91
|
```
|
136
92
|
|
137
|
-
|
138
|
-
|
139
|
-
4. Include third module in a class.
|
93
|
+
### :attr_module_configuration_hash, :attr_class_configuration_hash ###
|
140
94
|
|
141
|
-
|
142
|
-
|
143
|
-
class CascadingConfiguration::MockClass
|
144
|
-
include CascadingConfiguration::MockModule3
|
145
|
-
end
|
95
|
+
:attr_class_configuration_hash works like :attr_configuration_hash but does not cascade to instances.
|
146
96
|
|
147
|
-
|
148
|
-
|
149
|
-
* Verify inherited value
|
97
|
+
Define initial configuration in a module or class:
|
150
98
|
|
151
99
|
```ruby
|
100
|
+
module SomeModule
|
152
101
|
|
153
|
-
|
154
|
-
# => some_hash_configuration.should == { :module_value => :some_value }
|
155
|
-
end
|
102
|
+
include CascadingConfiguration::Hash
|
156
103
|
|
157
|
-
|
104
|
+
attr_class_configuration_hash :some_hash_setting
|
158
105
|
|
159
|
-
|
106
|
+
some_hash_setting # => nil
|
160
107
|
|
161
|
-
|
108
|
+
some_hash_setting[ :some_setting ] = :some_value
|
162
109
|
|
163
|
-
|
164
|
-
self.some_hash_configuration = { :another_value => :some_value }
|
165
|
-
end
|
110
|
+
some_hash_setting[ :some_setting ] # => :some_value
|
166
111
|
|
112
|
+
end
|
167
113
|
```
|
168
114
|
|
169
|
-
|
115
|
+
Include initial module in a module or class:
|
170
116
|
|
171
117
|
```ruby
|
118
|
+
class SomeClass
|
172
119
|
|
173
|
-
|
174
|
-
# => some_hash_configuration.should == { :another_value => :some_value }
|
175
|
-
end
|
176
|
-
|
177
|
-
```
|
178
|
-
|
179
|
-
## Instance of Top Class ##
|
120
|
+
include SomeModule
|
180
121
|
|
181
|
-
|
122
|
+
some_hash_setting[ :some_setting ] # => :some_value
|
182
123
|
|
183
|
-
|
124
|
+
self.some_hash_setting.replace( :some_other_setting => :some_other_value )
|
184
125
|
|
185
|
-
|
126
|
+
some_hash_setting # => { :some_other_setting => :some_other_value }
|
186
127
|
|
128
|
+
end
|
187
129
|
```
|
188
130
|
|
189
|
-
|
131
|
+
And it does not cascade to instances:
|
190
132
|
|
191
133
|
```ruby
|
134
|
+
instance = SomeClass.new
|
192
135
|
|
193
|
-
|
194
|
-
|
136
|
+
instance.respond_to?( :some_hash_setting ).should == false
|
195
137
|
```
|
196
138
|
|
197
|
-
|
198
|
-
|
199
|
-
```ruby
|
200
|
-
|
201
|
-
object_instance_one.some_hash_configuration = { :yet_another_value => :some_value }
|
139
|
+
### :attr_local_configuration_hash ###
|
202
140
|
|
203
|
-
|
141
|
+
:attr_local_configuration_hash works like :attr_configuration_hash but does not cascade. This is primarily useful for creating local configurations maintained in parallel with cascading configurations (for instance, with the same variable prefixes), for overriding the local configuration method, and for hiding the configuration variable (coming soon).
|
204
142
|
|
205
|
-
|
143
|
+
Define initial configuration in a module or class:
|
206
144
|
|
207
145
|
```ruby
|
146
|
+
module SomeModule
|
208
147
|
|
209
|
-
|
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.
|
148
|
+
include CascadingConfiguration::Hash
|
218
149
|
|
219
|
-
|
150
|
+
attr_class_configuration_hash :some_hash_setting
|
220
151
|
|
221
|
-
|
152
|
+
some_hash_setting # => nil
|
222
153
|
|
223
|
-
|
154
|
+
some_hash_setting[ :some_setting ] = :some_value
|
224
155
|
|
225
|
-
|
226
|
-
# => some_hash_configuration.should == { :another_value => :some_value }
|
227
|
-
end
|
156
|
+
some_hash_setting[ :some_setting ] # => :some_value
|
228
157
|
|
158
|
+
end
|
229
159
|
```
|
230
160
|
|
231
|
-
|
161
|
+
Include initial module in a module or class:
|
232
162
|
|
233
163
|
```ruby
|
164
|
+
class SomeClass
|
234
165
|
|
235
|
-
|
236
|
-
self.some_hash_configuration = { :a_value_not_yet_used => :some_value }
|
237
|
-
end
|
166
|
+
include SomeModule
|
238
167
|
|
239
|
-
|
168
|
+
respond_to?( :some_hash_setting ).should == false
|
240
169
|
|
241
|
-
|
170
|
+
end
|
171
|
+
```
|
242
172
|
|
243
|
-
|
173
|
+
## Additional Functionality ##
|
244
174
|
|
245
|
-
|
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
|
175
|
+
Cascading-configuration also provides several other convenience functions.
|
250
176
|
|
251
|
-
|
177
|
+
### Variable Name Prefixing ###
|
252
178
|
|
253
|
-
|
179
|
+
Configuration prefix can be set so that variables use property name with the configuration prefix prepended.
|
254
180
|
|
255
|
-
|
181
|
+
This can be done in order defined (current configuration prefix is stored for configuration), or it can be specified on a per-property basis.
|
256
182
|
|
257
183
|
```ruby
|
184
|
+
module SomeModule
|
258
185
|
|
259
|
-
|
186
|
+
include CascadingConfiguration
|
260
187
|
|
261
|
-
|
188
|
+
attr_configuration :some_setting
|
262
189
|
|
263
|
-
|
190
|
+
self.some_setting = :a_value
|
264
191
|
|
265
|
-
|
192
|
+
instance_variables.include?( :@some_setting ) # => true
|
266
193
|
|
267
|
-
#
|
268
|
-
|
269
|
-
# => CascadingConfiguration::MockClass.some_hash_configuration.should == { :another_value => :some_value }
|
270
|
-
# => CascadingConfiguration::MockModule.some_hash_configuration.should == { :some_value => :some_value }
|
194
|
+
# we can declare a prefix for specific properties
|
195
|
+
attr_configuration_prefix '__configuration_prefix__', :some_other_setting
|
271
196
|
|
272
|
-
|
197
|
+
attr_configuration :some_other_setting, :yet_another_setting
|
273
198
|
|
274
|
-
|
199
|
+
self.some_setting = :some_value
|
200
|
+
self.yet_another_setting = :another_value
|
275
201
|
|
276
|
-
|
202
|
+
instance_variables.include?( :@some_other_setting ) # => false
|
203
|
+
instance_variables.include?( :@__configuration_prefix__some_other_setting ) # => true
|
204
|
+
instance_variables.include?( :@yet_another_setting ) # => true
|
277
205
|
|
278
|
-
|
206
|
+
# or we can declare a prefix for all properties defined after prefix is declared
|
207
|
+
attr_configuration_prefix '__another_configuration_prefix__'
|
279
208
|
|
280
|
-
|
209
|
+
attr_configuration :still_another_prefix
|
281
210
|
|
282
|
-
|
283
|
-
|
284
|
-
end
|
211
|
+
instance_variables.include?( :@still_another_prefix ) # => false
|
212
|
+
instance_variables.include?( :@__another_configuration_prefix__still_another_prefix ) # => true
|
285
213
|
|
214
|
+
end
|
286
215
|
```
|
287
216
|
|
288
|
-
|
217
|
+
### Method Redefinition ###
|
289
218
|
|
290
|
-
|
291
|
-
|
292
|
-
class CascadingConfiguration::MockClassSub2 < CascadingConfiguration::MockClassSub1
|
293
|
-
self.some_hash_configuration = { :another_value_not_yet_used => :some_value }
|
294
|
-
end
|
219
|
+
Any declared configuration is defined in order to support locally redefining the method and accessing the original by calling super.
|
295
220
|
|
296
|
-
```
|
221
|
+
```ruby
|
222
|
+
module SomeModule
|
297
223
|
|
298
|
-
|
224
|
+
include CascadingConfiguration
|
299
225
|
|
300
|
-
|
226
|
+
attr_configuration :some_array_setting
|
301
227
|
|
302
|
-
|
303
|
-
|
228
|
+
def some_array_setting=( value )
|
229
|
+
puts 'Replacing configuration array!'
|
230
|
+
super
|
304
231
|
end
|
305
232
|
|
233
|
+
end
|
306
234
|
```
|
307
235
|
|
308
|
-
|
236
|
+
### Hidden Configuration ###
|
309
237
|
|
310
|
-
|
238
|
+
#### :attr_hide ####
|
311
239
|
|
312
|
-
|
313
|
-
|
314
|
-
object_instance_three = CascadingConfiguration::MockClassSub2.new
|
315
|
-
|
316
|
-
```
|
317
|
-
|
318
|
-
* Verify inherited value
|
240
|
+
Coming soon.
|
319
241
|
|
320
242
|
```ruby
|
243
|
+
module SomeModule
|
321
244
|
|
322
|
-
|
245
|
+
include CascadingConfiguration
|
323
246
|
|
324
|
-
|
247
|
+
attr_configuration :some_array_setting
|
325
248
|
|
326
|
-
|
249
|
+
instance_variables.include?( :@some_array_setting ) # => true
|
327
250
|
|
328
|
-
|
251
|
+
attr_hide :some_array_setting
|
329
252
|
|
330
|
-
|
253
|
+
instance_variables.include?( :@some_array_setting ) # => false
|
331
254
|
|
255
|
+
end
|
332
256
|
```
|
333
257
|
|
334
|
-
|
335
|
-
|
336
|
-
```ruby
|
337
|
-
|
338
|
-
# => object_instance_three.some_hash_configuration.should == { :one_more_unused_value => :some_value }
|
339
|
-
|
340
|
-
```
|
258
|
+
Causes configuration variable to be stored in external context so that it is not included in instance variables.
|
341
259
|
|
342
260
|
# License #
|
343
261
|
|
data/README.rdoc
CHANGED
@@ -1,30 +1,34 @@
|
|
1
1
|
== Cascading Configuration
|
2
2
|
|
3
|
-
http://rubygems.org/gems/cascading-configuration
|
3
|
+
http://rubygems.org/gems/cascading-configuration-hash
|
4
4
|
|
5
5
|
== Description
|
6
6
|
|
7
|
-
Adds methods for cascading
|
7
|
+
Adds methods for cascading configuration hashes. Support package for cascading-configuration.
|
8
8
|
|
9
9
|
== Summary
|
10
10
|
|
11
|
-
Cascading configuration methods for
|
11
|
+
Cascading configuration methods for hashes, which returns the appropriate lowest accumulated value. Configuration inheritance can cascade through modules, classes, and to instances.
|
12
|
+
|
13
|
+
This means that we can create configuration modules, optionally setting configuration defaults, and include those configuration modules in other modules or classes.
|
12
14
|
|
13
15
|
== :attr_configuration_hash
|
14
16
|
|
15
|
-
:
|
17
|
+
:attr_configuration_array provides inheritable hash configurations that cascade downward. A composite hash will be returned (merging downward from most distant ancestor to self).
|
18
|
+
|
19
|
+
An internal cache is kept, and any configuration updates that occur to higher-level ancestors cascade immediately downward.
|
16
20
|
|
17
|
-
|
21
|
+
:attr_class_configuration_hash works like :attr_configuration_hash but does not cascade to instances.
|
18
22
|
|
19
|
-
:attr_configuration_hash
|
23
|
+
:attr_local_configuration_hash works like :attr_configuration_hash but does not cascade. This is primarily useful for creating local configurations maintained in parallel with cascading configurations (for instance, with the same variable prefixes), for overriding the local configuration method, and for hiding the configuration variable (coming soon).
|
20
24
|
|
21
25
|
== Install
|
22
26
|
|
23
|
-
* sudo gem install cascading-configuration
|
27
|
+
* sudo gem install cascading-configuration-hash
|
24
28
|
|
25
29
|
== Usage
|
26
30
|
|
27
|
-
See
|
31
|
+
See README.md
|
28
32
|
|
29
33
|
== License
|
30
34
|
|
@@ -13,7 +13,7 @@ module CascadingConfiguration
|
|
13
13
|
class LocalConfigurationHash < Hash
|
14
14
|
end
|
15
15
|
module Hash
|
16
|
-
module
|
16
|
+
module AccessorDefinitionMethods
|
17
17
|
end
|
18
18
|
module Interface
|
19
19
|
end
|
@@ -30,6 +30,6 @@ require_relative 'cascading-configuration-hash/CascadingConfiguration/Compositin
|
|
30
30
|
require_relative 'cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb'
|
31
31
|
require_relative 'cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb'
|
32
32
|
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash.rb'
|
33
|
-
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/
|
33
|
+
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/AccessorDefinitionMethods.rb'
|
34
34
|
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb'
|
35
35
|
require_relative 'cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInclusionExtensionSupport.rb'
|
@@ -34,7 +34,7 @@ module CascadingConfiguration::Hash
|
|
34
34
|
class_or_module.instance_eval do
|
35
35
|
extend module_self
|
36
36
|
extend module_self::Interface
|
37
|
-
extend module_self::
|
37
|
+
extend module_self::AccessorDefinitionMethods
|
38
38
|
extend CascadingConfiguration::Hash::ModuleInclusionExtensionSupport unless is_a?( Class )
|
39
39
|
end
|
40
40
|
end
|
@@ -47,7 +47,7 @@ module CascadingConfiguration::Hash
|
|
47
47
|
module_self = self
|
48
48
|
class_or_module.instance_eval do
|
49
49
|
extend module_self::Interface
|
50
|
-
extend module_self::
|
50
|
+
extend module_self::AccessorDefinitionMethods
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
module CascadingConfiguration::Hash::
|
2
|
+
module CascadingConfiguration::Hash::AccessorDefinitionMethods
|
3
3
|
|
4
4
|
extend CascadingConfiguration::InternalModuleStub
|
5
5
|
|
@@ -9,8 +9,8 @@ module CascadingConfiguration::Hash::ConfigurationAccessors
|
|
9
9
|
|
10
10
|
def define_cascading_hash_setter( configuration_name )
|
11
11
|
configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
|
12
|
-
[ accessor_instance_support, accessor_module_support ].compact.each do |
|
13
|
-
|
12
|
+
[ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
|
13
|
+
accessor_module_support.module_eval do
|
14
14
|
define_method( configuration_setter_name ) do |hash|
|
15
15
|
# we want the hash to supplant existing config
|
16
16
|
return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
|
@@ -25,8 +25,8 @@ module CascadingConfiguration::Hash::ConfigurationAccessors
|
|
25
25
|
|
26
26
|
def define_cascading_hash_getter( configuration_name )
|
27
27
|
configuration_getter_name = configuration_name
|
28
|
-
[ accessor_instance_support, accessor_module_support ].compact.each do |
|
29
|
-
|
28
|
+
[ accessor_instance_support, accessor_module_support ].compact.each do |accessor_module_support|
|
29
|
+
accessor_module_support.module_eval do
|
30
30
|
define_method( configuration_getter_name ) do
|
31
31
|
return composite_hash_for_cascading_configuration( configuration_name )
|
32
32
|
end
|
@@ -67,7 +67,7 @@ module CascadingConfiguration::Hash::ConfigurationAccessors
|
|
67
67
|
|
68
68
|
def define_local_configuration_hash_setter( configuration_name )
|
69
69
|
configuration_setter_name = ( configuration_name.to_s + '=' ).to_sym
|
70
|
-
|
70
|
+
accessor_local_instance_support.module_eval do
|
71
71
|
define_method( configuration_setter_name ) do |hash|
|
72
72
|
# we want the hash to supplant existing config
|
73
73
|
return composite_hash_for_cascading_configuration( configuration_name ).replace( hash )
|
@@ -81,7 +81,7 @@ module CascadingConfiguration::Hash::ConfigurationAccessors
|
|
81
81
|
|
82
82
|
def define_local_configuration_hash_getter( configuration_name )
|
83
83
|
configuration_getter_name = configuration_name
|
84
|
-
|
84
|
+
accessor_local_instance_support.module_eval do
|
85
85
|
define_method( configuration_getter_name ) do
|
86
86
|
return composite_hash_for_cascading_configuration( configuration_name )
|
87
87
|
end
|
@@ -23,13 +23,13 @@ module CascadingConfiguration::Hash::Interface
|
|
23
23
|
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
#
|
28
|
-
|
26
|
+
####################################
|
27
|
+
# attr_module_configuration_hash #
|
28
|
+
####################################
|
29
29
|
|
30
30
|
# defines configuration in class or module
|
31
31
|
# configuration cascades downward to last class or module
|
32
|
-
def
|
32
|
+
def attr_module_configuration_hash( *property_names, & compositing_block )
|
33
33
|
|
34
34
|
property_names.each do |this_property_name|
|
35
35
|
accessor_module_support.set_compositing_proc( this_property_name, compositing_block ) if block_given?
|
@@ -42,6 +42,7 @@ module CascadingConfiguration::Hash::Interface
|
|
42
42
|
return self
|
43
43
|
|
44
44
|
end
|
45
|
+
alias_method :attr_class_configuration_hash, :attr_module_configuration_hash
|
45
46
|
|
46
47
|
###################################
|
47
48
|
# attr_local_configuration_hash #
|
@@ -50,7 +51,9 @@ module CascadingConfiguration::Hash::Interface
|
|
50
51
|
# defines configuration in present class or module context
|
51
52
|
# configuration does not cascade
|
52
53
|
def attr_local_configuration_hash( *property_names, & compositing_block )
|
53
|
-
|
54
|
+
|
55
|
+
CascadingConfiguration::Variable.define_accessor_local_instance_support( self )
|
56
|
+
|
54
57
|
property_names.each do |this_property_name|
|
55
58
|
accessor_module_support.set_compositing_proc( this_property_name, compositing_block ) if block_given?
|
56
59
|
# define configuration setter
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
require_relative '../../../lib/cascading-configuration-hash.rb'
|
3
3
|
|
4
|
-
describe CascadingConfiguration::Hash::
|
4
|
+
describe CascadingConfiguration::Hash::AccessorDefinitionMethods do
|
5
5
|
|
6
6
|
######################################
|
7
7
|
# define_cascading_hash_setter #
|
@@ -11,7 +11,7 @@ describe CascadingConfiguration::Hash::ConfigurationAccessors do
|
|
11
11
|
it 'can define a method to get and modify the configuration hash' do
|
12
12
|
class CascadingConfiguration::Hash::Mock
|
13
13
|
include CascadingConfiguration::Variable
|
14
|
-
extend CascadingConfiguration::Hash::
|
14
|
+
extend CascadingConfiguration::Hash::AccessorDefinitionMethods
|
15
15
|
include CascadingConfiguration::Hash::ObjectInstance
|
16
16
|
extend CascadingConfiguration::Hash::Interface
|
17
17
|
end
|
@@ -21,7 +21,7 @@ describe CascadingConfiguration::Hash do
|
|
21
21
|
# => instances of including classes get configurations
|
22
22
|
# => extending modules and classes get attr_configuration and configurations
|
23
23
|
# => instances of extending classes get nothing
|
24
|
-
module CascadingConfiguration::Hash::
|
24
|
+
module CascadingConfiguration::Hash::ConfigurationMockModuleExtended
|
25
25
|
extend CascadingConfiguration::Hash
|
26
26
|
# => singleton gets attr_configuration and configurations
|
27
27
|
respond_to?( :attr_configuration_hash ).should == true
|
@@ -33,31 +33,31 @@ describe CascadingConfiguration::Hash do
|
|
33
33
|
instance_methods.include?( :configuration_setting ).should == false
|
34
34
|
# => including modules and classes get nothing
|
35
35
|
module SubmoduleIncluding
|
36
|
-
include CascadingConfiguration::Hash::
|
36
|
+
include CascadingConfiguration::Hash::ConfigurationMockModuleExtended
|
37
37
|
instance_methods.include?( :configuration_setting ).should == false
|
38
38
|
respond_to?( :configuration_setting ).should == false
|
39
39
|
end
|
40
40
|
# => extending modules and classes get nothing
|
41
41
|
module SubmoduleExtending
|
42
|
-
extend CascadingConfiguration::Hash::
|
42
|
+
extend CascadingConfiguration::Hash::ConfigurationMockModuleExtended
|
43
43
|
instance_methods.include?( :configuration_setting ).should == false
|
44
44
|
respond_to?( :configuration_setting ).should == false
|
45
45
|
end
|
46
46
|
# => instances of including and extending classes get nothing
|
47
47
|
class ClassIncluding
|
48
|
-
include CascadingConfiguration::Hash::
|
48
|
+
include CascadingConfiguration::Hash::ConfigurationMockModuleExtended
|
49
49
|
instance_methods.include?( :configuration_setting ).should == false
|
50
50
|
respond_to?( :configuration_setting ).should == false
|
51
51
|
end
|
52
52
|
class ClassExtending
|
53
|
-
extend CascadingConfiguration::Hash::
|
53
|
+
extend CascadingConfiguration::Hash::ConfigurationMockModuleExtended
|
54
54
|
instance_methods.include?( :configuration_setting ).should == false
|
55
55
|
respond_to?( :configuration_setting ).should == false
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
# * module included with setting
|
60
|
-
module CascadingConfiguration::Hash::
|
60
|
+
module CascadingConfiguration::Hash::ConfigurationMockModuleIncluded
|
61
61
|
include CascadingConfiguration::Hash
|
62
62
|
# => singleton gets attr_configuration and configurations
|
63
63
|
respond_to?( :attr_configuration_hash ).should == true
|
@@ -69,7 +69,7 @@ describe CascadingConfiguration::Hash do
|
|
69
69
|
instance_methods.include?( :configuration_setting ).should == true
|
70
70
|
# => including modules and classes get attr_configuration and configurations
|
71
71
|
module SubmoduleIncluding
|
72
|
-
include CascadingConfiguration::Hash::
|
72
|
+
include CascadingConfiguration::Hash::ConfigurationMockModuleIncluded
|
73
73
|
instance_methods.include?( :configuration_setting ).should == true
|
74
74
|
respond_to?( :configuration_setting ).should == true
|
75
75
|
configuration_setting.should == { :a_configuration => :some_value }
|
@@ -81,7 +81,7 @@ describe CascadingConfiguration::Hash do
|
|
81
81
|
end
|
82
82
|
# => extending modules and classes get attr_configuration and configurations
|
83
83
|
module SubmoduleExtending
|
84
|
-
extend CascadingConfiguration::Hash::
|
84
|
+
extend CascadingConfiguration::Hash::ConfigurationMockModuleIncluded
|
85
85
|
# if we're extended then we want to use the eigenclass ancestor chain
|
86
86
|
# - the first ancestor will be the extending module
|
87
87
|
# - the rest of the ancestors will be the extending module's include chain
|
@@ -96,7 +96,7 @@ describe CascadingConfiguration::Hash do
|
|
96
96
|
end
|
97
97
|
# => instances of including classes get configurations
|
98
98
|
class ClassIncluding
|
99
|
-
include CascadingConfiguration::Hash::
|
99
|
+
include CascadingConfiguration::Hash::ConfigurationMockModuleIncluded
|
100
100
|
instance_methods.include?( :configuration_setting ).should == true
|
101
101
|
respond_to?( :configuration_setting ).should == true
|
102
102
|
configuration_setting.should == { :a_configuration => :some_value }
|
@@ -111,7 +111,7 @@ describe CascadingConfiguration::Hash do
|
|
111
111
|
setting_class_including_instance.configuration_setting.should == { :a_configuration => :some_value }
|
112
112
|
setting_class_including_instance.configuration_setting.delete( :a_configuration )
|
113
113
|
class ClassExtending
|
114
|
-
extend CascadingConfiguration::Hash::
|
114
|
+
extend CascadingConfiguration::Hash::ConfigurationMockModuleIncluded
|
115
115
|
respond_to?( :configuration_setting ).should == true
|
116
116
|
configuration_setting.should == { :a_configuration => :some_value }
|
117
117
|
configuration_setting[ :other_setting ] = :some_value
|
@@ -124,8 +124,8 @@ describe CascadingConfiguration::Hash do
|
|
124
124
|
setting_class_including_instance.respond_to?( :configuration_setting ).should == false
|
125
125
|
end
|
126
126
|
|
127
|
-
class CascadingConfiguration::Hash::
|
128
|
-
include CascadingConfiguration::Hash::
|
127
|
+
class CascadingConfiguration::Hash::ConfigurationMockClass
|
128
|
+
include CascadingConfiguration::Hash::ConfigurationMockModuleIncluded::SubmoduleIncluding
|
129
129
|
configuration_setting.should == { :a_configuration => :some_value }
|
130
130
|
configuration_setting[ :other_setting ] = :some_value
|
131
131
|
configuration_setting.should == { :a_configuration => :some_value,
|
@@ -134,20 +134,20 @@ describe CascadingConfiguration::Hash do
|
|
134
134
|
configuration_setting.should == { :a_configuration => :some_value }
|
135
135
|
end
|
136
136
|
|
137
|
-
object_instance_one = CascadingConfiguration::Hash::
|
137
|
+
object_instance_one = CascadingConfiguration::Hash::ConfigurationMockClass.new
|
138
138
|
object_instance_one.configuration_setting.should == { :a_configuration => :some_value }
|
139
139
|
object_instance_one.configuration_setting[ :some_other_configuration ] = :some_value
|
140
140
|
object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
|
141
141
|
:some_other_configuration => :some_value }
|
142
142
|
|
143
|
-
class CascadingConfiguration::Hash::
|
143
|
+
class CascadingConfiguration::Hash::ConfigurationMockClassSub1 < CascadingConfiguration::Hash::ConfigurationMockClass
|
144
144
|
configuration_setting.should == { :a_configuration => :some_value }
|
145
145
|
self.configuration_setting[ :another_configuration ] = :some_value
|
146
146
|
configuration_setting.should == { :a_configuration => :some_value,
|
147
147
|
:another_configuration => :some_value }
|
148
148
|
end
|
149
149
|
|
150
|
-
object_instance_two = CascadingConfiguration::Hash::
|
150
|
+
object_instance_two = CascadingConfiguration::Hash::ConfigurationMockClassSub1.new
|
151
151
|
object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
|
152
152
|
:another_configuration => :some_value }
|
153
153
|
object_instance_two.configuration_setting[ :some_other_configuration ] = :some_value
|
@@ -156,13 +156,13 @@ describe CascadingConfiguration::Hash do
|
|
156
156
|
:some_other_configuration => :some_value }
|
157
157
|
|
158
158
|
# change ancestor setting
|
159
|
-
CascadingConfiguration::Hash::
|
160
|
-
CascadingConfiguration::Hash::
|
159
|
+
CascadingConfiguration::Hash::ConfigurationMockClass.configuration_setting[ :a_yet_unused_configuration ] = :some_value
|
160
|
+
CascadingConfiguration::Hash::ConfigurationMockClass.configuration_setting.should == { :a_configuration => :some_value,
|
161
161
|
:a_yet_unused_configuration => :some_value }
|
162
162
|
object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
|
163
163
|
:a_yet_unused_configuration => :some_value,
|
164
164
|
:some_other_configuration => :some_value }
|
165
|
-
CascadingConfiguration::Hash::
|
165
|
+
CascadingConfiguration::Hash::ConfigurationMockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
|
166
166
|
:a_yet_unused_configuration => :some_value,
|
167
167
|
:another_configuration => :some_value }
|
168
168
|
object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
|
@@ -175,18 +175,18 @@ describe CascadingConfiguration::Hash do
|
|
175
175
|
object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
|
176
176
|
:a_yet_unused_configuration => :some_value,
|
177
177
|
:some_other_configuration => :some_value }
|
178
|
-
CascadingConfiguration::Hash::
|
179
|
-
CascadingConfiguration::Hash::
|
178
|
+
CascadingConfiguration::Hash::ConfigurationMockClassSub1.configuration_setting.freeze!
|
179
|
+
CascadingConfiguration::Hash::ConfigurationMockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
|
180
180
|
:a_yet_unused_configuration => :some_value,
|
181
181
|
:another_configuration => :some_value }
|
182
|
-
CascadingConfiguration::Hash::
|
183
|
-
CascadingConfiguration::Hash::
|
182
|
+
CascadingConfiguration::Hash::ConfigurationMockClass.configuration_setting[ :non_cascading_configuration ] = :some_value
|
183
|
+
CascadingConfiguration::Hash::ConfigurationMockClass.configuration_setting.should == { :a_configuration => :some_value,
|
184
184
|
:a_yet_unused_configuration => :some_value,
|
185
185
|
:non_cascading_configuration => :some_value }
|
186
186
|
object_instance_one.configuration_setting.should == { :a_configuration => :some_value,
|
187
187
|
:a_yet_unused_configuration => :some_value,
|
188
188
|
:some_other_configuration => :some_value }
|
189
|
-
CascadingConfiguration::Hash::
|
189
|
+
CascadingConfiguration::Hash::ConfigurationMockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
|
190
190
|
:a_yet_unused_configuration => :some_value,
|
191
191
|
:another_configuration => :some_value }
|
192
192
|
object_instance_two.configuration_setting.should == { :a_configuration => :some_value,
|
@@ -194,7 +194,7 @@ describe CascadingConfiguration::Hash do
|
|
194
194
|
:another_configuration => :some_value,
|
195
195
|
:some_other_configuration => :some_value }
|
196
196
|
|
197
|
-
module CascadingConfiguration::Hash::
|
197
|
+
module CascadingConfiguration::Hash::ConfigurationMockModule
|
198
198
|
include CascadingConfiguration::Hash
|
199
199
|
attr_configuration_hash :some_hash do |parent_hash, composite_hash|
|
200
200
|
parent_hash.each do |this_key, this_data|
|
@@ -210,8 +210,8 @@ describe CascadingConfiguration::Hash do
|
|
210
210
|
self.some_hash.should == { :one => 1, :two => 2 }
|
211
211
|
end
|
212
212
|
|
213
|
-
module CascadingConfiguration::Hash::
|
214
|
-
include CascadingConfiguration::Hash::
|
213
|
+
module CascadingConfiguration::Hash::ConfigurationMockModule2
|
214
|
+
include CascadingConfiguration::Hash::ConfigurationMockModule
|
215
215
|
self.some_hash.should == { :one => 1, :two => 2 }
|
216
216
|
self.some_hash.replace( { :one => 1, :two => 2 } )
|
217
217
|
self.some_hash.should == { :one => 0, :two => 0 }
|
@@ -219,4 +219,314 @@ describe CascadingConfiguration::Hash do
|
|
219
219
|
|
220
220
|
end
|
221
221
|
|
222
|
+
####################################
|
223
|
+
# attr_module_configuration_hash #
|
224
|
+
# attr_class_configuration_hash #
|
225
|
+
####################################
|
226
|
+
|
227
|
+
it 'can define a class configuration hash, which will not cascade to instances' do
|
228
|
+
|
229
|
+
# possibilities:
|
230
|
+
# * module extended with setting
|
231
|
+
# => singleton gets attr_configuration and configurations
|
232
|
+
# => including modules and classes get nothing
|
233
|
+
# => extending modules and classes get nothing
|
234
|
+
# => instances of including and extending classes get nothing
|
235
|
+
# * module included with setting
|
236
|
+
# => singleton gets attr_configuration and configurations
|
237
|
+
# => including modules and classes get attr_configuration and configurations
|
238
|
+
# => instances of including classes get configurations
|
239
|
+
# => extending modules and classes get attr_configuration and configurations
|
240
|
+
# => instances of extending classes get nothing
|
241
|
+
module CascadingConfiguration::Hash::ClassConfigurationMockModuleExtended
|
242
|
+
extend CascadingConfiguration::Hash
|
243
|
+
# => singleton gets attr_configuration and configurations
|
244
|
+
respond_to?( :attr_module_configuration_hash ).should == true
|
245
|
+
method( :attr_module_configuration_hash ).should == method( :attr_class_configuration_hash )
|
246
|
+
attr_module_configuration_hash :configuration_setting
|
247
|
+
respond_to?( :configuration_setting ).should == true
|
248
|
+
configuration_setting.should == {}
|
249
|
+
self.configuration_setting[ :a_configuration ] = :some_value
|
250
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
251
|
+
instance_methods.include?( :configuration_setting ).should == false
|
252
|
+
# => including modules and classes get nothing
|
253
|
+
module SubmoduleIncluding
|
254
|
+
include CascadingConfiguration::Hash::ClassConfigurationMockModuleExtended
|
255
|
+
instance_methods.include?( :configuration_setting ).should == false
|
256
|
+
respond_to?( :configuration_setting ).should == false
|
257
|
+
end
|
258
|
+
# => extending modules and classes get nothing
|
259
|
+
module SubmoduleExtending
|
260
|
+
extend CascadingConfiguration::Hash::ClassConfigurationMockModuleExtended
|
261
|
+
instance_methods.include?( :configuration_setting ).should == false
|
262
|
+
respond_to?( :configuration_setting ).should == false
|
263
|
+
end
|
264
|
+
# => instances of including and extending classes get nothing
|
265
|
+
class ClassIncluding
|
266
|
+
include CascadingConfiguration::Hash::ClassConfigurationMockModuleExtended
|
267
|
+
instance_methods.include?( :configuration_setting ).should == false
|
268
|
+
respond_to?( :configuration_setting ).should == false
|
269
|
+
end
|
270
|
+
class ClassExtending
|
271
|
+
extend CascadingConfiguration::Hash::ClassConfigurationMockModuleExtended
|
272
|
+
instance_methods.include?( :configuration_setting ).should == false
|
273
|
+
respond_to?( :configuration_setting ).should == false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
# * module included with setting
|
278
|
+
module CascadingConfiguration::Hash::ClassConfigurationMockModuleIncluded
|
279
|
+
include CascadingConfiguration::Hash
|
280
|
+
# => singleton gets attr_configuration and configurations
|
281
|
+
respond_to?( :attr_module_configuration_hash ).should == true
|
282
|
+
attr_module_configuration_hash :configuration_setting
|
283
|
+
respond_to?( :configuration_setting ).should == true
|
284
|
+
configuration_setting.should == {}
|
285
|
+
self.configuration_setting[ :a_configuration ] = :some_value
|
286
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
287
|
+
instance_methods.include?( :configuration_setting ).should == false
|
288
|
+
# => including modules and classes get attr_configuration and configurations
|
289
|
+
module SubmoduleIncluding
|
290
|
+
include CascadingConfiguration::Hash::ClassConfigurationMockModuleIncluded
|
291
|
+
instance_methods.include?( :configuration_setting ).should == false
|
292
|
+
respond_to?( :configuration_setting ).should == true
|
293
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
294
|
+
configuration_setting[ :other_setting ] = :some_value
|
295
|
+
configuration_setting.should == { :a_configuration => :some_value,
|
296
|
+
:other_setting => :some_value }
|
297
|
+
configuration_setting.delete( :other_setting ).should == :some_value
|
298
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
299
|
+
end
|
300
|
+
# => extending modules and classes get attr_configuration and configurations
|
301
|
+
module SubmoduleExtending
|
302
|
+
extend CascadingConfiguration::Hash::ClassConfigurationMockModuleIncluded
|
303
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
304
|
+
# - the first ancestor will be the extending module
|
305
|
+
# - the rest of the ancestors will be the extending module's include chain
|
306
|
+
respond_to?( :configuration_setting ).should == true
|
307
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
308
|
+
configuration_setting[ :other_setting ] = :some_value
|
309
|
+
configuration_setting.should == { :a_configuration => :some_value,
|
310
|
+
:other_setting => :some_value }
|
311
|
+
configuration_setting.delete( :other_setting ).should == :some_value
|
312
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
313
|
+
instance_methods.include?( :configuration_setting ).should == false
|
314
|
+
end
|
315
|
+
# => instances of including classes get configurations
|
316
|
+
class ClassIncluding
|
317
|
+
include CascadingConfiguration::Hash::ClassConfigurationMockModuleIncluded
|
318
|
+
instance_methods.include?( :configuration_setting ).should == false
|
319
|
+
respond_to?( :configuration_setting ).should == true
|
320
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
321
|
+
configuration_setting[ :other_setting ] = :some_value
|
322
|
+
configuration_setting.should == { :a_configuration => :some_value,
|
323
|
+
:other_setting => :some_value }
|
324
|
+
configuration_setting.delete( :other_setting ).should == :some_value
|
325
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
326
|
+
end
|
327
|
+
setting_class_including_instance = ClassIncluding.new
|
328
|
+
setting_class_including_instance.respond_to?( :configuration_setting ).should == false
|
329
|
+
class ClassExtending
|
330
|
+
extend CascadingConfiguration::Hash::ClassConfigurationMockModuleIncluded
|
331
|
+
respond_to?( :configuration_setting ).should == true
|
332
|
+
instance_methods.include?( :configuration_setting ).should == false
|
333
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
334
|
+
configuration_setting[ :other_setting ] = :some_value
|
335
|
+
configuration_setting.should == { :a_configuration => :some_value,
|
336
|
+
:other_setting => :some_value }
|
337
|
+
configuration_setting.delete( :other_setting ).should == :some_value
|
338
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
339
|
+
end
|
340
|
+
setting_class_including_instance = ClassExtending.new
|
341
|
+
setting_class_including_instance.respond_to?( :configuration_setting ).should == false
|
342
|
+
end
|
343
|
+
|
344
|
+
class CascadingConfiguration::Hash::ClassConfigurationMockClass
|
345
|
+
include CascadingConfiguration::Hash::ClassConfigurationMockModuleIncluded::SubmoduleIncluding
|
346
|
+
respond_to?( :configuration_setting ).should == true
|
347
|
+
instance_methods.include?( :configuration_setting ).should == false
|
348
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
349
|
+
configuration_setting[ :other_setting ] = :some_value
|
350
|
+
configuration_setting.should == { :a_configuration => :some_value,
|
351
|
+
:other_setting => :some_value }
|
352
|
+
configuration_setting.delete( :other_setting ).should == :some_value
|
353
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
354
|
+
end
|
355
|
+
|
356
|
+
object_instance_one = CascadingConfiguration::Hash::ClassConfigurationMockClass.new
|
357
|
+
object_instance_one.respond_to?( :a_configuration ).should == false
|
358
|
+
|
359
|
+
class CascadingConfiguration::Hash::ClassConfigurationMockClassSub1 < CascadingConfiguration::Hash::ClassConfigurationMockClass
|
360
|
+
respond_to?( :configuration_setting ).should == true
|
361
|
+
instance_methods.include?( :configuration_setting ).should == false
|
362
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
363
|
+
self.configuration_setting[ :another_configuration ] = :some_value
|
364
|
+
configuration_setting.should == { :a_configuration => :some_value,
|
365
|
+
:another_configuration => :some_value }
|
366
|
+
end
|
367
|
+
|
368
|
+
object_instance_two = CascadingConfiguration::Hash::ClassConfigurationMockClassSub1.new
|
369
|
+
object_instance_two.respond_to?( :a_configuration ).should == false
|
370
|
+
|
371
|
+
# change ancestor setting
|
372
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClass.configuration_setting[ :a_yet_unused_configuration ] = :some_value
|
373
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClass.configuration_setting.should == { :a_configuration => :some_value,
|
374
|
+
:a_yet_unused_configuration => :some_value }
|
375
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
|
376
|
+
:a_yet_unused_configuration => :some_value,
|
377
|
+
:another_configuration => :some_value }
|
378
|
+
|
379
|
+
# freeze ancestor setting
|
380
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClassSub1.configuration_setting.freeze!
|
381
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
|
382
|
+
:a_yet_unused_configuration => :some_value,
|
383
|
+
:another_configuration => :some_value }
|
384
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClass.configuration_setting[ :non_cascading_configuration ] = :some_value
|
385
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClass.configuration_setting.should == { :a_configuration => :some_value,
|
386
|
+
:a_yet_unused_configuration => :some_value,
|
387
|
+
:non_cascading_configuration => :some_value }
|
388
|
+
CascadingConfiguration::Hash::ClassConfigurationMockClassSub1.configuration_setting.should == { :a_configuration => :some_value,
|
389
|
+
:a_yet_unused_configuration => :some_value,
|
390
|
+
:another_configuration => :some_value }
|
391
|
+
|
392
|
+
module CascadingConfiguration::Hash::ClassConfigurationMockModule
|
393
|
+
include CascadingConfiguration::Hash
|
394
|
+
attr_module_configuration_hash :some_hash do |parent_hash, composite_hash|
|
395
|
+
parent_hash.each do |this_key, this_data|
|
396
|
+
if existing_value = composite_hash[ this_key ]
|
397
|
+
composite_hash[ this_key ] = this_data - existing_value
|
398
|
+
else
|
399
|
+
composite_hash[ this_key ] = this_data
|
400
|
+
end
|
401
|
+
end
|
402
|
+
composite_hash
|
403
|
+
end
|
404
|
+
self.some_hash = { :one => 1, :two => 2 }
|
405
|
+
self.some_hash.should == { :one => 1, :two => 2 }
|
406
|
+
end
|
407
|
+
|
408
|
+
module CascadingConfiguration::Hash::ClassConfigurationMockModule2
|
409
|
+
include CascadingConfiguration::Hash::ClassConfigurationMockModule
|
410
|
+
self.some_hash.should == { :one => 1, :two => 2 }
|
411
|
+
self.some_hash.replace( { :one => 1, :two => 2 } )
|
412
|
+
self.some_hash.should == { :one => 0, :two => 0 }
|
413
|
+
end
|
414
|
+
|
415
|
+
end
|
416
|
+
|
417
|
+
###################################
|
418
|
+
# attr_local_configuration_hash #
|
419
|
+
###################################
|
420
|
+
|
421
|
+
it 'can define a local configuration hash, which will not cascade' do
|
422
|
+
|
423
|
+
# possibilities:
|
424
|
+
# * module extended with setting
|
425
|
+
# => singleton gets attr_configuration and configurations
|
426
|
+
# => including modules and classes get nothing
|
427
|
+
# => extending modules and classes get nothing
|
428
|
+
# => instances of including and extending classes get nothing
|
429
|
+
# * module included with setting
|
430
|
+
# => singleton gets attr_configuration and configurations
|
431
|
+
# => including modules and classes get attr_configuration and configurations
|
432
|
+
# => instances of including classes get configurations
|
433
|
+
# => extending modules and classes get attr_configuration and configurations
|
434
|
+
# => instances of extending classes get nothing
|
435
|
+
module CascadingConfiguration::Hash::LocalConfigurationMockModuleExtended
|
436
|
+
extend CascadingConfiguration::Hash
|
437
|
+
# => singleton gets attr_configuration and configurations
|
438
|
+
respond_to?( :attr_local_configuration_hash ).should == true
|
439
|
+
attr_local_configuration_hash :configuration_setting
|
440
|
+
respond_to?( :configuration_setting ).should == true
|
441
|
+
configuration_setting.should == {}
|
442
|
+
self.configuration_setting[ :a_configuration ] = :some_value
|
443
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
444
|
+
instance_methods.include?( :configuration_setting ).should == false
|
445
|
+
# => including modules and classes get nothing
|
446
|
+
module SubmoduleIncluding
|
447
|
+
include CascadingConfiguration::Hash::LocalConfigurationMockModuleExtended
|
448
|
+
instance_methods.include?( :configuration_setting ).should == false
|
449
|
+
respond_to?( :configuration_setting ).should == false
|
450
|
+
end
|
451
|
+
# => extending modules and classes get nothing
|
452
|
+
module SubmoduleExtending
|
453
|
+
extend CascadingConfiguration::Hash::LocalConfigurationMockModuleExtended
|
454
|
+
instance_methods.include?( :configuration_setting ).should == false
|
455
|
+
respond_to?( :configuration_setting ).should == false
|
456
|
+
end
|
457
|
+
# => instances of including and extending classes get nothing
|
458
|
+
class ClassIncluding
|
459
|
+
include CascadingConfiguration::Hash::LocalConfigurationMockModuleExtended
|
460
|
+
instance_methods.include?( :configuration_setting ).should == false
|
461
|
+
respond_to?( :configuration_setting ).should == false
|
462
|
+
end
|
463
|
+
class ClassExtending
|
464
|
+
extend CascadingConfiguration::Hash::LocalConfigurationMockModuleExtended
|
465
|
+
instance_methods.include?( :configuration_setting ).should == false
|
466
|
+
respond_to?( :configuration_setting ).should == false
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
# * module included with setting
|
471
|
+
module CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
|
472
|
+
include CascadingConfiguration::Hash
|
473
|
+
# => singleton gets attr_configuration and configurations
|
474
|
+
respond_to?( :attr_local_configuration_hash ).should == true
|
475
|
+
attr_local_configuration_hash :configuration_setting
|
476
|
+
respond_to?( :configuration_setting ).should == true
|
477
|
+
configuration_setting.should == {}
|
478
|
+
self.configuration_setting[ :a_configuration ] = :some_value
|
479
|
+
configuration_setting.should == { :a_configuration => :some_value }
|
480
|
+
instance_methods.include?( :configuration_setting ).should == false
|
481
|
+
# => including modules and classes get attr_configuration and configurations
|
482
|
+
module SubmoduleIncluding
|
483
|
+
include CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
|
484
|
+
instance_methods.include?( :configuration_setting ).should == false
|
485
|
+
respond_to?( :configuration_setting ).should == false
|
486
|
+
end
|
487
|
+
# => extending modules and classes get attr_configuration and configurations
|
488
|
+
module SubmoduleExtending
|
489
|
+
extend CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
|
490
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
491
|
+
# - the first ancestor will be the extending module
|
492
|
+
# - the rest of the ancestors will be the extending module's include chain
|
493
|
+
instance_methods.include?( :configuration_setting ).should == false
|
494
|
+
respond_to?( :configuration_setting ).should == false
|
495
|
+
end
|
496
|
+
# => instances of including classes get configurations
|
497
|
+
class ClassIncluding
|
498
|
+
include CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
|
499
|
+
instance_methods.include?( :configuration_setting ).should == false
|
500
|
+
respond_to?( :configuration_setting ).should == false
|
501
|
+
end
|
502
|
+
setting_class_including_instance = ClassIncluding.new
|
503
|
+
setting_class_including_instance.respond_to?( :configuration_setting ).should == false
|
504
|
+
class ClassExtending
|
505
|
+
extend CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded
|
506
|
+
instance_methods.include?( :configuration_setting ).should == false
|
507
|
+
respond_to?( :configuration_setting ).should == false
|
508
|
+
end
|
509
|
+
setting_class_including_instance = ClassExtending.new
|
510
|
+
setting_class_including_instance.respond_to?( :configuration_setting ).should == false
|
511
|
+
end
|
512
|
+
|
513
|
+
class CascadingConfiguration::Hash::LocalConfigurationMockClass
|
514
|
+
include CascadingConfiguration::Hash::LocalConfigurationMockModuleIncluded::SubmoduleIncluding
|
515
|
+
instance_methods.include?( :configuration_setting ).should == false
|
516
|
+
respond_to?( :configuration_setting ).should == false
|
517
|
+
end
|
518
|
+
|
519
|
+
object_instance_one = CascadingConfiguration::Hash::LocalConfigurationMockClass.new
|
520
|
+
object_instance_one.respond_to?( :a_configuration ).should == false
|
521
|
+
|
522
|
+
class CascadingConfiguration::Hash::LocalConfigurationMockClassSub1 < CascadingConfiguration::Hash::LocalConfigurationMockClass
|
523
|
+
instance_methods.include?( :configuration_setting ).should == false
|
524
|
+
respond_to?( :configuration_setting ).should == false
|
525
|
+
end
|
526
|
+
|
527
|
+
object_instance_two = CascadingConfiguration::Hash::LocalConfigurationMockClassSub1.new
|
528
|
+
object_instance_two.respond_to?( :a_configuration ).should == false
|
529
|
+
|
530
|
+
end
|
531
|
+
|
222
532
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 1.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Asher
|
@@ -43,14 +43,14 @@ files:
|
|
43
43
|
- lib/cascading-configuration-hash/CascadingConfiguration/_private_/LocalConfigurationHash.rb
|
44
44
|
- lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash/Instance.rb
|
45
45
|
- lib/cascading-configuration-hash/CascadingConfiguration/CompositingHash.rb
|
46
|
-
- lib/cascading-configuration-hash/CascadingConfiguration/Hash/
|
46
|
+
- lib/cascading-configuration-hash/CascadingConfiguration/Hash/AccessorDefinitionMethods.rb
|
47
47
|
- lib/cascading-configuration-hash/CascadingConfiguration/Hash/Interface.rb
|
48
48
|
- lib/cascading-configuration-hash/CascadingConfiguration/Hash/ModuleInclusionExtensionSupport.rb
|
49
49
|
- lib/cascading-configuration-hash/CascadingConfiguration/Hash.rb
|
50
50
|
- lib/cascading-configuration-hash/CascadingConfiguration/LocalConfigurationHash.rb
|
51
51
|
- lib/cascading-configuration-hash.rb
|
52
52
|
- spec/CascadingConfiguration/CascadingCompositeHash_spec.rb
|
53
|
-
- spec/CascadingConfiguration/Hash/
|
53
|
+
- spec/CascadingConfiguration/Hash/AccessorDefinitionMethods_spec.rb
|
54
54
|
- spec/CascadingConfiguration/Hash_spec.rb
|
55
55
|
- spec/CascadingConfiguration/LocalConfigurationHash_spec.rb
|
56
56
|
- README.md
|