cascading_configuration 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +40 -0
- data/README.md +211 -0
- data/lib/cascading_configuration/array/sorted/unique.rb +110 -0
- data/lib/cascading_configuration/array/sorted.rb +106 -0
- data/lib/cascading_configuration/array/unique.rb +106 -0
- data/lib/cascading_configuration/array.rb +103 -0
- data/lib/cascading_configuration/core/enable_instance_support.rb +22 -0
- data/lib/cascading_configuration/core/enable_module_support.rb +24 -0
- data/lib/cascading_configuration/core/encapsulation.rb +343 -0
- data/lib/cascading_configuration/core/instance_controller/extension_module.rb +38 -0
- data/lib/cascading_configuration/core/instance_controller/support_module/instance_support_module.rb +21 -0
- data/lib/cascading_configuration/core/instance_controller/support_module/singleton_support_module.rb +21 -0
- data/lib/cascading_configuration/core/instance_controller/support_module.rb +253 -0
- data/lib/cascading_configuration/core/instance_controller.rb +840 -0
- data/lib/cascading_configuration/core/module/block_configurations/cascading_variables.rb +129 -0
- data/lib/cascading_configuration/core/module/block_configurations.rb +15 -0
- data/lib/cascading_configuration/core/module/extended_configurations/compositing_objects.rb +173 -0
- data/lib/cascading_configuration/core/module/extended_configurations.rb +65 -0
- data/lib/cascading_configuration/core/module/inheriting_values.rb +64 -0
- data/lib/cascading_configuration/core/module.rb +284 -0
- data/lib/cascading_configuration/core.rb +23 -0
- data/lib/cascading_configuration/hash.rb +103 -0
- data/lib/cascading_configuration/setting.rb +87 -0
- data/lib/cascading_configuration.rb +47 -0
- data/lib/namespaces.rb +9 -0
- data/lib/requires.rb +46 -0
- data/spec/cascading_configuration/array/sorted/unique_spec.rb +742 -0
- data/spec/cascading_configuration/array/sorted_spec.rb +741 -0
- data/spec/cascading_configuration/array/unique_spec.rb +746 -0
- data/spec/cascading_configuration/array_spec.rb +768 -0
- data/spec/cascading_configuration/core/encapsulation_spec.rb +208 -0
- data/spec/cascading_configuration/core/instance_controller/extension_module_spec.rb +26 -0
- data/spec/cascading_configuration/core/instance_controller/support_module_spec.rb +269 -0
- data/spec/cascading_configuration/core/instance_controller_spec.rb +273 -0
- data/spec/cascading_configuration/core/module/block_configurations/cascading_variables_spec.rb +17 -0
- data/spec/cascading_configuration/core/module/extended_configurations/compositing_objects_spec.rb +127 -0
- data/spec/cascading_configuration/core/module/extended_configurations_spec.rb +37 -0
- data/spec/cascading_configuration/core/module/inheriting_values_spec.rb +87 -0
- data/spec/cascading_configuration/core/module_spec.rb +491 -0
- data/spec/cascading_configuration/hash_spec.rb +826 -0
- data/spec/cascading_configuration/setting_spec.rb +687 -0
- data/spec/cascading_configuration_spec.rb +58 -0
- metadata +185 -0
@@ -0,0 +1,687 @@
|
|
1
|
+
|
2
|
+
require_relative '../../lib/cascading_configuration.rb'
|
3
|
+
|
4
|
+
describe CascadingConfiguration::Setting do
|
5
|
+
|
6
|
+
##################
|
7
|
+
# attr_setting #
|
8
|
+
##################
|
9
|
+
|
10
|
+
it 'can define a configuration setting, which is the primary interface' do
|
11
|
+
|
12
|
+
# extending a module or class works like a finalizer for the cascading configuration
|
13
|
+
# if the configuration is re-opened at a later point (including or extending a lower ancestor)
|
14
|
+
# then the configuration will still cascade upward
|
15
|
+
# this permits ancestors in the heirarchy to skip out on configurations
|
16
|
+
# upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
|
17
|
+
|
18
|
+
# possibilities:
|
19
|
+
# * module extended with setting
|
20
|
+
module ::CascadingConfiguration::Setting::ConfigurationMockExtended
|
21
|
+
extend CascadingConfiguration::Setting
|
22
|
+
# => singleton gets attr_setting and configurations
|
23
|
+
respond_to?( :attr_setting ).should == true
|
24
|
+
respond_to?( :attr_configuration ).should == true
|
25
|
+
attr_setting :some_configuration, :some_other_configuration
|
26
|
+
respond_to?( :some_configuration ).should == true
|
27
|
+
self.some_configuration = :our_setting_value
|
28
|
+
some_configuration.should == :our_setting_value
|
29
|
+
method_defined?( :some_configuration ).should == false
|
30
|
+
instance_variables.empty?.should == true
|
31
|
+
# => including modules and classes get nothing
|
32
|
+
module SubmoduleIncluding
|
33
|
+
include CascadingConfiguration::Setting::ConfigurationMockExtended
|
34
|
+
method_defined?( :some_configuration ).should == false
|
35
|
+
respond_to?( :some_configuration ).should == false
|
36
|
+
instance_variables.empty?.should == true
|
37
|
+
end
|
38
|
+
# => extending modules and classes get nothing
|
39
|
+
module SubmoduleExtending
|
40
|
+
extend CascadingConfiguration::Setting::ConfigurationMockExtended
|
41
|
+
method_defined?( :some_configuration ).should == false
|
42
|
+
respond_to?( :some_configuration ).should == false
|
43
|
+
instance_variables.empty?.should == true
|
44
|
+
end
|
45
|
+
# => instances of including and extending classes get nothing
|
46
|
+
class ClassIncluding
|
47
|
+
include CascadingConfiguration::Setting::ConfigurationMockExtended
|
48
|
+
method_defined?( :some_configuration ).should == false
|
49
|
+
respond_to?( :some_configuration ).should == false
|
50
|
+
instance_variables.empty?.should == true
|
51
|
+
end
|
52
|
+
class ClassExtending
|
53
|
+
extend CascadingConfiguration::Setting::ConfigurationMockExtended
|
54
|
+
method_defined?( :some_configuration ).should == false
|
55
|
+
respond_to?( :some_configuration ).should == false
|
56
|
+
instance_variables.empty?.should == true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# * module included with setting
|
61
|
+
module ::CascadingConfiguration::Setting::ConfigurationMockIncluded
|
62
|
+
include CascadingConfiguration::Setting
|
63
|
+
# => singleton gets attr_setting and configurations
|
64
|
+
eigenclass = class << self ; self ; end
|
65
|
+
respond_to?( :attr_setting ).should == true
|
66
|
+
attr_setting :some_configuration
|
67
|
+
respond_to?( :some_configuration ).should == true
|
68
|
+
self.some_configuration = :our_setting_value
|
69
|
+
some_configuration.should == :our_setting_value
|
70
|
+
method_defined?( :some_configuration ).should == true
|
71
|
+
instance_variables.empty?.should == true
|
72
|
+
# => including modules and classes get attr_setting and configurations
|
73
|
+
module SubmoduleIncluding
|
74
|
+
include CascadingConfiguration::Setting::ConfigurationMockIncluded
|
75
|
+
method_defined?( :some_configuration ).should == true
|
76
|
+
respond_to?( :some_configuration ).should == true
|
77
|
+
some_configuration.should == :our_setting_value
|
78
|
+
self.some_configuration = :another_configuration
|
79
|
+
some_configuration.should == :another_configuration
|
80
|
+
instance_variables.empty?.should == true
|
81
|
+
end
|
82
|
+
# => extending modules and classes get attr_setting and configurations
|
83
|
+
module SubmoduleExtending
|
84
|
+
extend CascadingConfiguration::Setting::ConfigurationMockIncluded
|
85
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
86
|
+
# - the first ancestor will be the extending module
|
87
|
+
# - the rest of the ancestors will be the extending module's include chain
|
88
|
+
respond_to?( :some_configuration ).should == true
|
89
|
+
some_configuration.should == :our_setting_value
|
90
|
+
self.some_configuration = :some_other_configuration
|
91
|
+
some_configuration.should == :some_other_configuration
|
92
|
+
method_defined?( :some_configuration ).should == false
|
93
|
+
instance_variables.empty?.should == true
|
94
|
+
end
|
95
|
+
# => instances of including classes get configurations
|
96
|
+
class ClassIncluding
|
97
|
+
include CascadingConfiguration::Setting::ConfigurationMockIncluded
|
98
|
+
method_defined?( :some_configuration ).should == true
|
99
|
+
respond_to?( :some_configuration ).should == true
|
100
|
+
some_configuration.should == :our_setting_value
|
101
|
+
self.some_configuration = :another_configuration
|
102
|
+
some_configuration.should == :another_configuration
|
103
|
+
instance_variables.empty?.should == true
|
104
|
+
end
|
105
|
+
setting_class_including_instance = ClassIncluding.new
|
106
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == true
|
107
|
+
setting_class_including_instance.some_configuration.should == :another_configuration
|
108
|
+
self.some_configuration = :our_setting_value
|
109
|
+
some_configuration.should == :our_setting_value
|
110
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
111
|
+
# => instances of extending classes get nothing
|
112
|
+
class ClassExtending
|
113
|
+
extend CascadingConfiguration::Setting::ConfigurationMockIncluded
|
114
|
+
respond_to?( :some_configuration ).should == true
|
115
|
+
some_configuration.should == :our_setting_value
|
116
|
+
self.some_configuration = :some_other_configuration
|
117
|
+
some_configuration.should == :some_other_configuration
|
118
|
+
method_defined?( :some_configuration ).should == false
|
119
|
+
instance_variables.empty?.should == true
|
120
|
+
end
|
121
|
+
setting_class_including_instance = ClassExtending.new
|
122
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
123
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
124
|
+
end
|
125
|
+
|
126
|
+
class CascadingConfiguration::Setting::ConfigurationMockClass
|
127
|
+
include CascadingConfiguration::Setting::ConfigurationMockIncluded::SubmoduleIncluding
|
128
|
+
respond_to?( :some_configuration ).should == true
|
129
|
+
some_configuration.should == :another_configuration
|
130
|
+
self.some_configuration = :our_setting_value
|
131
|
+
some_configuration.should == :our_setting_value
|
132
|
+
instance_variables.empty?.should == true
|
133
|
+
end
|
134
|
+
class CascadingConfiguration::Setting::ConfigurationMockClassSub1 < CascadingConfiguration::Setting::ConfigurationMockClass
|
135
|
+
some_configuration.should == :our_setting_value
|
136
|
+
self.some_configuration = :our_other_setting_value
|
137
|
+
some_configuration.should == :our_other_setting_value
|
138
|
+
instance_variables.empty?.should == true
|
139
|
+
end
|
140
|
+
class CascadingConfiguration::Setting::ConfigurationMockClassSub2 < CascadingConfiguration::Setting::ConfigurationMockClassSub1
|
141
|
+
some_configuration.should == :our_other_setting_value
|
142
|
+
self.some_configuration = :a_third_setting_value
|
143
|
+
some_configuration.should == :a_third_setting_value
|
144
|
+
instance_variables.empty?.should == true
|
145
|
+
end
|
146
|
+
|
147
|
+
module SomeModule
|
148
|
+
include CascadingConfiguration::Setting
|
149
|
+
attr_setting :some_configuration
|
150
|
+
self.some_configuration = :another_configuration
|
151
|
+
end
|
152
|
+
module OtherModule
|
153
|
+
include SomeModule
|
154
|
+
end
|
155
|
+
Object.new.instance_eval do
|
156
|
+
extend( OtherModule )
|
157
|
+
respond_to?( :some_configuration ).should == true
|
158
|
+
some_configuration.should == :another_configuration
|
159
|
+
self.some_configuration = :our_setting_value
|
160
|
+
some_configuration.should == :our_setting_value
|
161
|
+
instance_variables.empty?.should == true
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
#########################
|
167
|
+
# attr_module_setting #
|
168
|
+
# attr_class_setting #
|
169
|
+
#########################
|
170
|
+
|
171
|
+
it 'can define a class configuration setting, which will not cascade to instances' do
|
172
|
+
|
173
|
+
# extending a module or class works like a finalizer for the cascading configuration
|
174
|
+
# if the configuration is re-opened at a later point (including or extending a lower ancestor)
|
175
|
+
# then the configuration will still cascade upward
|
176
|
+
# this permits ancestors in the hierarchy to skip out on configurations
|
177
|
+
# upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
|
178
|
+
|
179
|
+
# possibilities:
|
180
|
+
# * module extended with setting
|
181
|
+
module ::CascadingConfiguration::Setting::ClassConfigurationMockExtended
|
182
|
+
extend CascadingConfiguration::Setting
|
183
|
+
# => singleton gets attr_module_configuration and configurations
|
184
|
+
respond_to?( :attr_module_setting ).should == true
|
185
|
+
respond_to?( :attr_module_configuration ).should == true
|
186
|
+
method( :attr_module_configuration ).should == method( :attr_class_configuration )
|
187
|
+
attr_module_configuration :some_configuration
|
188
|
+
respond_to?( :attr_module_configuration ).should == true
|
189
|
+
self.some_configuration = :our_setting_value
|
190
|
+
some_configuration.should == :our_setting_value
|
191
|
+
method_defined?( :some_configuration ).should == false
|
192
|
+
instance_variables.empty?.should == true
|
193
|
+
# => including modules and classes get nothing
|
194
|
+
module SubmoduleIncluding
|
195
|
+
include CascadingConfiguration::Setting::ClassConfigurationMockExtended
|
196
|
+
method_defined?( :some_configuration ).should == false
|
197
|
+
respond_to?( :some_configuration ).should == false
|
198
|
+
instance_variables.empty?.should == true
|
199
|
+
end
|
200
|
+
# => extending modules and classes get nothing
|
201
|
+
module SubmoduleExtending
|
202
|
+
extend CascadingConfiguration::Setting::ClassConfigurationMockExtended
|
203
|
+
method_defined?( :some_configuration ).should == false
|
204
|
+
respond_to?( :some_configuration ).should == false
|
205
|
+
instance_variables.empty?.should == true
|
206
|
+
end
|
207
|
+
# => instances of including and extending classes get nothing
|
208
|
+
class ClassIncluding
|
209
|
+
include CascadingConfiguration::Setting::ClassConfigurationMockExtended
|
210
|
+
method_defined?( :some_configuration ).should == false
|
211
|
+
respond_to?( :some_configuration ).should == false
|
212
|
+
instance_variables.empty?.should == true
|
213
|
+
end
|
214
|
+
class ClassExtending
|
215
|
+
extend CascadingConfiguration::Setting::ClassConfigurationMockExtended
|
216
|
+
method_defined?( :some_configuration ).should == false
|
217
|
+
respond_to?( :some_configuration ).should == false
|
218
|
+
instance_variables.empty?.should == true
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# * module included with setting
|
223
|
+
module ::CascadingConfiguration::Setting::ClassConfigurationMockIncluded
|
224
|
+
include CascadingConfiguration::Setting
|
225
|
+
# => singleton gets attr_module_configuration and configurations
|
226
|
+
respond_to?( :attr_module_configuration ).should == true
|
227
|
+
attr_module_configuration :some_configuration
|
228
|
+
respond_to?( :some_configuration ).should == true
|
229
|
+
self.some_configuration = :our_setting_value
|
230
|
+
some_configuration.should == :our_setting_value
|
231
|
+
method_defined?( :some_configuration ).should == false
|
232
|
+
instance_variables.empty?.should == true
|
233
|
+
# => including modules and classes get attr_module_configuration and configurations
|
234
|
+
module SubmoduleIncluding
|
235
|
+
include CascadingConfiguration::Setting::ClassConfigurationMockIncluded
|
236
|
+
method_defined?( :some_configuration ).should == false
|
237
|
+
respond_to?( :some_configuration ).should == true
|
238
|
+
some_configuration.should == :our_setting_value
|
239
|
+
self.some_configuration = :another_configuration
|
240
|
+
some_configuration.should == :another_configuration
|
241
|
+
instance_variables.empty?.should == true
|
242
|
+
end
|
243
|
+
# => extending modules and classes get attr_module_configuration and configurations
|
244
|
+
module SubmoduleExtending
|
245
|
+
extend CascadingConfiguration::Setting::ClassConfigurationMockIncluded
|
246
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
247
|
+
# - the first ancestor will be the extending module
|
248
|
+
# - the rest of the ancestors will be the extending module's include chain
|
249
|
+
respond_to?( :some_configuration ).should == false
|
250
|
+
method_defined?( :some_configuration ).should == false
|
251
|
+
instance_variables.empty?.should == true
|
252
|
+
end
|
253
|
+
# => instances of including classes get configurations
|
254
|
+
class ClassIncluding
|
255
|
+
include CascadingConfiguration::Setting::ClassConfigurationMockIncluded
|
256
|
+
method_defined?( :some_configuration ).should == false
|
257
|
+
respond_to?( :some_configuration ).should == true
|
258
|
+
some_configuration.should == :our_setting_value
|
259
|
+
self.some_configuration = :another_configuration
|
260
|
+
some_configuration.should == :another_configuration
|
261
|
+
instance_variables.empty?.should == true
|
262
|
+
end
|
263
|
+
setting_class_including_instance = ClassIncluding.new
|
264
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
265
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
266
|
+
# => instances of extending classes get nothing
|
267
|
+
class ClassExtending
|
268
|
+
extend CascadingConfiguration::Setting::ClassConfigurationMockIncluded
|
269
|
+
respond_to?( :some_configuration ).should == false
|
270
|
+
method_defined?( :some_configuration ).should == false
|
271
|
+
instance_variables.empty?.should == true
|
272
|
+
end
|
273
|
+
setting_class_including_instance = ClassExtending.new
|
274
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
275
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
276
|
+
end
|
277
|
+
|
278
|
+
class CascadingConfiguration::Setting::ClassConfigurationMockClass
|
279
|
+
include CascadingConfiguration::Setting::ClassConfigurationMockIncluded::SubmoduleIncluding
|
280
|
+
respond_to?( :some_configuration ).should == true
|
281
|
+
some_configuration.should == :another_configuration
|
282
|
+
self.some_configuration = :our_setting_value
|
283
|
+
some_configuration.should == :our_setting_value
|
284
|
+
instance_variables.empty?.should == true
|
285
|
+
end
|
286
|
+
class CascadingConfiguration::Setting::ClassConfigurationMockClassSub1 < CascadingConfiguration::Setting::ClassConfigurationMockClass
|
287
|
+
some_configuration.should == :our_setting_value
|
288
|
+
self.some_configuration = :our_other_setting_value
|
289
|
+
some_configuration.should == :our_other_setting_value
|
290
|
+
instance_variables.empty?.should == true
|
291
|
+
end
|
292
|
+
class CascadingConfiguration::Setting::ClassConfigurationMockClassSub2 < CascadingConfiguration::Setting::ClassConfigurationMockClassSub1
|
293
|
+
some_configuration.should == :our_other_setting_value
|
294
|
+
self.some_configuration = :a_third_setting_value
|
295
|
+
some_configuration.should == :a_third_setting_value
|
296
|
+
instance_variables.empty?.should == true
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
########################
|
302
|
+
# attr_local_setting #
|
303
|
+
########################
|
304
|
+
|
305
|
+
it 'can define a local configuration setting, which cascades to the first class and instances' do
|
306
|
+
|
307
|
+
# extending a module or class works like a finalizer for the cascading configuration
|
308
|
+
# if the configuration is re-opened at a later point (including or extending a lower ancestor)
|
309
|
+
# then the configuration will still cascade upward
|
310
|
+
# this permits ancestors in the heirarchy to skip out on configurations
|
311
|
+
# upward cascade can be frozen at any point using :freeze!, which will prevent further upward lookup
|
312
|
+
|
313
|
+
# possibilities:
|
314
|
+
# * module extended with setting
|
315
|
+
module ::CascadingConfiguration::Setting::LocalConfigurationMockExtended
|
316
|
+
extend CascadingConfiguration::Setting
|
317
|
+
# => singleton gets attr_setting and configurations
|
318
|
+
respond_to?( :attr_local_setting ).should == true
|
319
|
+
respond_to?( :attr_local_configuration ).should == true
|
320
|
+
attr_local_configuration :some_configuration
|
321
|
+
respond_to?( :some_configuration ).should == true
|
322
|
+
self.some_configuration = :our_setting_value
|
323
|
+
some_configuration.should == :our_setting_value
|
324
|
+
method_defined?( :some_configuration ).should == false
|
325
|
+
instance_variables.empty?.should == true
|
326
|
+
# => including modules and classes get nothing
|
327
|
+
module SubmoduleIncluding
|
328
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockExtended
|
329
|
+
method_defined?( :some_configuration ).should == false
|
330
|
+
respond_to?( :some_configuration ).should == false
|
331
|
+
instance_variables.empty?.should == true
|
332
|
+
end
|
333
|
+
# => extending modules and classes get nothing
|
334
|
+
module SubmoduleExtending
|
335
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockExtended
|
336
|
+
method_defined?( :some_configuration ).should == false
|
337
|
+
respond_to?( :some_configuration ).should == false
|
338
|
+
instance_variables.empty?.should == true
|
339
|
+
end
|
340
|
+
# => instances of including and extending classes get nothing
|
341
|
+
class ClassIncluding
|
342
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockExtended
|
343
|
+
method_defined?( :some_configuration ).should == false
|
344
|
+
respond_to?( :some_configuration ).should == false
|
345
|
+
instance_variables.empty?.should == true
|
346
|
+
end
|
347
|
+
class ClassExtending
|
348
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockExtended
|
349
|
+
method_defined?( :some_configuration ).should == false
|
350
|
+
respond_to?( :some_configuration ).should == false
|
351
|
+
instance_variables.empty?.should == true
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
# * module included with setting
|
356
|
+
module ::CascadingConfiguration::Setting::LocalConfigurationMockIncluded
|
357
|
+
include CascadingConfiguration::Setting
|
358
|
+
# => singleton gets attr_setting and configurations
|
359
|
+
respond_to?( :attr_local_configuration ).should == true
|
360
|
+
attr_local_configuration :some_configuration
|
361
|
+
respond_to?( :some_configuration ).should == true
|
362
|
+
self.some_configuration = :our_setting_value
|
363
|
+
some_configuration.should == :our_setting_value
|
364
|
+
method_defined?( :some_configuration ).should == true
|
365
|
+
instance_variables.empty?.should == true
|
366
|
+
# => including modules and classes get attr_setting and configurations
|
367
|
+
module SubmoduleIncluding
|
368
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockIncluded
|
369
|
+
method_defined?( :some_configuration ).should == true
|
370
|
+
respond_to?( :some_configuration ).should == false
|
371
|
+
instance_variables.empty?.should == true
|
372
|
+
end
|
373
|
+
module SubSubmoduleIncluding
|
374
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubmoduleIncluding
|
375
|
+
method_defined?( :some_configuration ).should == true
|
376
|
+
respond_to?( :some_configuration ).should == false
|
377
|
+
instance_variables.empty?.should == true
|
378
|
+
end
|
379
|
+
# => extending modules and classes get attr_setting and configurations
|
380
|
+
module SubmoduleExtending
|
381
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded
|
382
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
383
|
+
# - the first ancestor will be the extending module
|
384
|
+
# - the rest of the ancestors will be the extending module's include chain
|
385
|
+
respond_to?( :some_configuration ).should == true
|
386
|
+
method_defined?( :some_configuration ).should == false
|
387
|
+
instance_variables.empty?.should == true
|
388
|
+
end
|
389
|
+
module SubSubmoduleExtending
|
390
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubmoduleExtending
|
391
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
392
|
+
# - the first ancestor will be the extending module
|
393
|
+
# - the rest of the ancestors will be the extending module's include chain
|
394
|
+
respond_to?( :some_configuration ).should == false
|
395
|
+
method_defined?( :some_configuration ).should == false
|
396
|
+
instance_variables.empty?.should == true
|
397
|
+
end
|
398
|
+
# => instances of including classes get configurations
|
399
|
+
class ClassIncluding
|
400
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockIncluded
|
401
|
+
method_defined?( :some_configuration ).should == true
|
402
|
+
respond_to?( :some_configuration ).should == false
|
403
|
+
instance_variables.empty?.should == true
|
404
|
+
end
|
405
|
+
setting_class_including_instance = ClassIncluding.new
|
406
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == true
|
407
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
408
|
+
# => instances of extending classes get nothing
|
409
|
+
class ClassExtending
|
410
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded
|
411
|
+
respond_to?( :some_configuration ).should == true
|
412
|
+
method_defined?( :some_configuration ).should == false
|
413
|
+
instance_variables.empty?.should == true
|
414
|
+
end
|
415
|
+
setting_class_including_instance = ClassExtending.new
|
416
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
417
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
418
|
+
class ClassSubSubmoduleIncludingIncluding
|
419
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
|
420
|
+
respond_to?( :some_configuration ).should == false
|
421
|
+
method_defined?( :some_configuration ).should == true
|
422
|
+
instance_variables.empty?.should == true
|
423
|
+
end
|
424
|
+
setting_class_including_instance = ClassSubSubmoduleIncludingIncluding.new
|
425
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == true
|
426
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
427
|
+
class ClassSubSubmoduleIncludingExtending
|
428
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
|
429
|
+
respond_to?( :some_configuration ).should == true
|
430
|
+
method_defined?( :some_configuration ).should == false
|
431
|
+
instance_variables.empty?.should == true
|
432
|
+
end
|
433
|
+
setting_class_including_instance = ClassSubSubmoduleIncludingExtending.new
|
434
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
435
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
436
|
+
class ClassSubSubmoduleIncludingIncludingAndExtending
|
437
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
|
438
|
+
extend CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubSubmoduleIncluding
|
439
|
+
respond_to?( :some_configuration ).should == true
|
440
|
+
method_defined?( :some_configuration ).should == true
|
441
|
+
instance_variables.empty?.should == true
|
442
|
+
end
|
443
|
+
setting_class_including_instance = ClassSubSubmoduleIncludingIncludingAndExtending.new
|
444
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == true
|
445
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
446
|
+
end
|
447
|
+
|
448
|
+
class CascadingConfiguration::Setting::LocalConfigurationMockClass
|
449
|
+
include CascadingConfiguration::Setting::LocalConfigurationMockIncluded::SubmoduleIncluding
|
450
|
+
respond_to?( :some_configuration ).should == false
|
451
|
+
instance_variables.empty?.should == true
|
452
|
+
end
|
453
|
+
class CascadingConfiguration::Setting::LocalConfigurationMockClassSub1 < CascadingConfiguration::Setting::LocalConfigurationMockClass
|
454
|
+
respond_to?( :some_configuration ).should == false
|
455
|
+
instance_variables.empty?.should == true
|
456
|
+
end
|
457
|
+
class CascadingConfiguration::Setting::LocalConfigurationMockClassSub2 < CascadingConfiguration::Setting::LocalConfigurationMockClassSub1
|
458
|
+
respond_to?( :some_configuration ).should == false
|
459
|
+
instance_variables.empty?.should == true
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
###########################
|
464
|
+
# attr_instance_setting #
|
465
|
+
###########################
|
466
|
+
|
467
|
+
it 'can define a configuration setting for the present instance, which will not cascade' do
|
468
|
+
|
469
|
+
# possibilities:
|
470
|
+
# * module extended with setting
|
471
|
+
module ::CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
472
|
+
extend CascadingConfiguration::Setting
|
473
|
+
# => singleton gets attr_setting and configurations
|
474
|
+
respond_to?( :attr_instance_setting ).should == true
|
475
|
+
respond_to?( :attr_instance_configuration ).should == true
|
476
|
+
method_defined?( :some_configuration ).should == false
|
477
|
+
instance_variables.empty?.should == true
|
478
|
+
# => including modules and classes get nothing
|
479
|
+
module SubmoduleIncluding
|
480
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
481
|
+
method_defined?( :some_configuration ).should == false
|
482
|
+
respond_to?( :some_configuration ).should == false
|
483
|
+
instance_variables.empty?.should == true
|
484
|
+
end
|
485
|
+
# => extending modules and classes get nothing
|
486
|
+
module SubmoduleExtending
|
487
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
488
|
+
method_defined?( :some_configuration ).should == false
|
489
|
+
respond_to?( :some_configuration ).should == false
|
490
|
+
instance_variables.empty?.should == true
|
491
|
+
end
|
492
|
+
# => instances of including and extending classes get nothing
|
493
|
+
class ClassIncluding
|
494
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
495
|
+
method_defined?( :some_configuration ).should == false
|
496
|
+
respond_to?( :some_configuration ).should == false
|
497
|
+
instance_variables.empty?.should == true
|
498
|
+
end
|
499
|
+
class ClassExtending
|
500
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockExtended
|
501
|
+
method_defined?( :some_configuration ).should == false
|
502
|
+
respond_to?( :some_configuration ).should == false
|
503
|
+
instance_variables.empty?.should == true
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
# * module included with setting
|
508
|
+
module ::CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
509
|
+
include CascadingConfiguration::Setting
|
510
|
+
# => singleton gets attr_setting and configurations
|
511
|
+
respond_to?( :attr_instance_configuration ).should == true
|
512
|
+
respond_to?( :some_configuration ).should == false
|
513
|
+
attr_instance_configuration :some_configuration
|
514
|
+
respond_to?( :some_configuration ).should == false
|
515
|
+
method_defined?( :some_configuration ).should == true
|
516
|
+
instance_variables.empty?.should == true
|
517
|
+
# => including modules and classes get attr_setting and configurations
|
518
|
+
module SubmoduleIncluding
|
519
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
520
|
+
method_defined?( :some_configuration ).should == true
|
521
|
+
respond_to?( :some_configuration ).should == false
|
522
|
+
instance_variables.empty?.should == true
|
523
|
+
end
|
524
|
+
# => extending modules and classes get attr_setting and configurations
|
525
|
+
module SubmoduleExtending
|
526
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
527
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
528
|
+
# - the first ancestor will be the extending module
|
529
|
+
# - the rest of the ancestors will be the extending module's include chain
|
530
|
+
respond_to?( :some_configuration ).should == true
|
531
|
+
method_defined?( :some_configuration ).should == false
|
532
|
+
instance_variables.empty?.should == true
|
533
|
+
end
|
534
|
+
# => instances of including classes get configurations
|
535
|
+
class ClassIncluding
|
536
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
537
|
+
method_defined?( :some_configuration ).should == true
|
538
|
+
respond_to?( :some_configuration ).should == false
|
539
|
+
instance_variables.empty?.should == true
|
540
|
+
end
|
541
|
+
setting_class_including_instance = ClassIncluding.new
|
542
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == true
|
543
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
544
|
+
# => instances of extending classes get nothing
|
545
|
+
class ClassExtending
|
546
|
+
extend CascadingConfiguration::Setting::InstanceConfigurationMockIncluded
|
547
|
+
respond_to?( :some_configuration ).should == true
|
548
|
+
method_defined?( :some_configuration ).should == false
|
549
|
+
instance_variables.empty?.should == true
|
550
|
+
end
|
551
|
+
setting_class_including_instance = ClassExtending.new
|
552
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
553
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
554
|
+
end
|
555
|
+
|
556
|
+
class CascadingConfiguration::Setting::InstanceConfigurationMockClass
|
557
|
+
include CascadingConfiguration::Setting::InstanceConfigurationMockIncluded::SubmoduleIncluding
|
558
|
+
respond_to?( :some_configuration ).should == false
|
559
|
+
method_defined?( :some_configuration ).should == true
|
560
|
+
instance_variables.empty?.should == true
|
561
|
+
end
|
562
|
+
class CascadingConfiguration::Setting::InstanceConfigurationMockClassSub1 < CascadingConfiguration::Setting::InstanceConfigurationMockClass
|
563
|
+
respond_to?( :some_configuration ).should == false
|
564
|
+
method_defined?( :some_configuration ).should == true
|
565
|
+
instance_variables.empty?.should == true
|
566
|
+
end
|
567
|
+
class CascadingConfiguration::Setting::InstanceConfigurationMockClassSub2 < CascadingConfiguration::Setting::InstanceConfigurationMockClassSub1
|
568
|
+
respond_to?( :some_configuration ).should == false
|
569
|
+
method_defined?( :some_configuration ).should == true
|
570
|
+
instance_variables.empty?.should == true
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
#########################
|
575
|
+
# attr_object_setting #
|
576
|
+
#########################
|
577
|
+
|
578
|
+
it 'can define a configuration setting for the present instance, which will not cascade' do
|
579
|
+
|
580
|
+
# possibilities:
|
581
|
+
# * module extended with setting
|
582
|
+
module ::CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
583
|
+
extend CascadingConfiguration::Setting
|
584
|
+
# => singleton gets attr_setting and configurations
|
585
|
+
respond_to?( :attr_object_setting ).should == true
|
586
|
+
respond_to?( :attr_object_configuration ).should == true
|
587
|
+
attr_object_configuration :some_configuration
|
588
|
+
respond_to?( :some_configuration ).should == true
|
589
|
+
self.some_configuration = :our_setting_value
|
590
|
+
some_configuration.should == :our_setting_value
|
591
|
+
method_defined?( :some_configuration ).should == false
|
592
|
+
instance_variables.empty?.should == true
|
593
|
+
# => including modules and classes get nothing
|
594
|
+
module SubmoduleIncluding
|
595
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
596
|
+
method_defined?( :some_configuration ).should == false
|
597
|
+
respond_to?( :some_configuration ).should == false
|
598
|
+
instance_variables.empty?.should == true
|
599
|
+
end
|
600
|
+
# => extending modules and classes get nothing
|
601
|
+
module SubmoduleExtending
|
602
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
603
|
+
method_defined?( :some_configuration ).should == false
|
604
|
+
respond_to?( :some_configuration ).should == false
|
605
|
+
instance_variables.empty?.should == true
|
606
|
+
end
|
607
|
+
# => instances of including and extending classes get nothing
|
608
|
+
class ClassIncluding
|
609
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
610
|
+
method_defined?( :some_configuration ).should == false
|
611
|
+
respond_to?( :some_configuration ).should == false
|
612
|
+
instance_variables.empty?.should == true
|
613
|
+
end
|
614
|
+
class ClassExtending
|
615
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockExtended
|
616
|
+
method_defined?( :some_configuration ).should == false
|
617
|
+
respond_to?( :some_configuration ).should == false
|
618
|
+
instance_variables.empty?.should == true
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
# * module included with setting
|
623
|
+
module ::CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
624
|
+
include CascadingConfiguration::Setting
|
625
|
+
# => singleton gets attr_setting and configurations
|
626
|
+
respond_to?( :attr_object_configuration ).should == true
|
627
|
+
attr_object_configuration :some_configuration
|
628
|
+
respond_to?( :some_configuration ).should == true
|
629
|
+
self.some_configuration = :our_setting_value
|
630
|
+
some_configuration.should == :our_setting_value
|
631
|
+
method_defined?( :some_configuration ).should == false
|
632
|
+
instance_variables.empty?.should == true
|
633
|
+
# => including modules and classes get attr_setting and configurations
|
634
|
+
module SubmoduleIncluding
|
635
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
636
|
+
method_defined?( :some_configuration ).should == false
|
637
|
+
respond_to?( :some_configuration ).should == false
|
638
|
+
instance_variables.empty?.should == true
|
639
|
+
end
|
640
|
+
# => extending modules and classes get attr_setting and configurations
|
641
|
+
module SubmoduleExtending
|
642
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
643
|
+
# if we're extended then we want to use the eigenclass ancestor chain
|
644
|
+
# - the first ancestor will be the extending module
|
645
|
+
# - the rest of the ancestors will be the extending module's include chain
|
646
|
+
respond_to?( :some_configuration ).should == false
|
647
|
+
method_defined?( :some_configuration ).should == false
|
648
|
+
instance_variables.empty?.should == true
|
649
|
+
end
|
650
|
+
# => instances of including classes get configurations
|
651
|
+
class ClassIncluding
|
652
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
653
|
+
method_defined?( :some_configuration ).should == false
|
654
|
+
respond_to?( :some_configuration ).should == false
|
655
|
+
instance_variables.empty?.should == true
|
656
|
+
end
|
657
|
+
setting_class_including_instance = ClassIncluding.new
|
658
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
659
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
660
|
+
# => instances of extending classes get nothing
|
661
|
+
class ClassExtending
|
662
|
+
extend CascadingConfiguration::Setting::ObjectConfigurationMockIncluded
|
663
|
+
respond_to?( :some_configuration ).should == false
|
664
|
+
method_defined?( :some_configuration ).should == false
|
665
|
+
instance_variables.empty?.should == true
|
666
|
+
end
|
667
|
+
setting_class_including_instance = ClassExtending.new
|
668
|
+
setting_class_including_instance.respond_to?( :some_configuration ).should == false
|
669
|
+
setting_class_including_instance.instance_variables.empty?.should == true
|
670
|
+
end
|
671
|
+
|
672
|
+
class CascadingConfiguration::Setting::ObjectConfigurationMockClass
|
673
|
+
include CascadingConfiguration::Setting::ObjectConfigurationMockIncluded::SubmoduleIncluding
|
674
|
+
respond_to?( :some_configuration ).should == false
|
675
|
+
instance_variables.empty?.should == true
|
676
|
+
end
|
677
|
+
class CascadingConfiguration::Setting::ObjectConfigurationMockClassSub1 < CascadingConfiguration::Setting::ObjectConfigurationMockClass
|
678
|
+
respond_to?( :some_configuration ).should == false
|
679
|
+
instance_variables.empty?.should == true
|
680
|
+
end
|
681
|
+
class CascadingConfiguration::Setting::ObjectConfigurationMockClassSub2 < CascadingConfiguration::Setting::ObjectConfigurationMockClassSub1
|
682
|
+
respond_to?( :some_configuration ).should == false
|
683
|
+
instance_variables.empty?.should == true
|
684
|
+
end
|
685
|
+
end
|
686
|
+
|
687
|
+
end
|