cascading_configuration 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/CHANGELOG.md +40 -0
  2. data/README.md +211 -0
  3. data/lib/cascading_configuration/array/sorted/unique.rb +110 -0
  4. data/lib/cascading_configuration/array/sorted.rb +106 -0
  5. data/lib/cascading_configuration/array/unique.rb +106 -0
  6. data/lib/cascading_configuration/array.rb +103 -0
  7. data/lib/cascading_configuration/core/enable_instance_support.rb +22 -0
  8. data/lib/cascading_configuration/core/enable_module_support.rb +24 -0
  9. data/lib/cascading_configuration/core/encapsulation.rb +343 -0
  10. data/lib/cascading_configuration/core/instance_controller/extension_module.rb +38 -0
  11. data/lib/cascading_configuration/core/instance_controller/support_module/instance_support_module.rb +21 -0
  12. data/lib/cascading_configuration/core/instance_controller/support_module/singleton_support_module.rb +21 -0
  13. data/lib/cascading_configuration/core/instance_controller/support_module.rb +253 -0
  14. data/lib/cascading_configuration/core/instance_controller.rb +840 -0
  15. data/lib/cascading_configuration/core/module/block_configurations/cascading_variables.rb +129 -0
  16. data/lib/cascading_configuration/core/module/block_configurations.rb +15 -0
  17. data/lib/cascading_configuration/core/module/extended_configurations/compositing_objects.rb +173 -0
  18. data/lib/cascading_configuration/core/module/extended_configurations.rb +65 -0
  19. data/lib/cascading_configuration/core/module/inheriting_values.rb +64 -0
  20. data/lib/cascading_configuration/core/module.rb +284 -0
  21. data/lib/cascading_configuration/core.rb +23 -0
  22. data/lib/cascading_configuration/hash.rb +103 -0
  23. data/lib/cascading_configuration/setting.rb +87 -0
  24. data/lib/cascading_configuration.rb +47 -0
  25. data/lib/namespaces.rb +9 -0
  26. data/lib/requires.rb +46 -0
  27. data/spec/cascading_configuration/array/sorted/unique_spec.rb +742 -0
  28. data/spec/cascading_configuration/array/sorted_spec.rb +741 -0
  29. data/spec/cascading_configuration/array/unique_spec.rb +746 -0
  30. data/spec/cascading_configuration/array_spec.rb +768 -0
  31. data/spec/cascading_configuration/core/encapsulation_spec.rb +208 -0
  32. data/spec/cascading_configuration/core/instance_controller/extension_module_spec.rb +26 -0
  33. data/spec/cascading_configuration/core/instance_controller/support_module_spec.rb +269 -0
  34. data/spec/cascading_configuration/core/instance_controller_spec.rb +273 -0
  35. data/spec/cascading_configuration/core/module/block_configurations/cascading_variables_spec.rb +17 -0
  36. data/spec/cascading_configuration/core/module/extended_configurations/compositing_objects_spec.rb +127 -0
  37. data/spec/cascading_configuration/core/module/extended_configurations_spec.rb +37 -0
  38. data/spec/cascading_configuration/core/module/inheriting_values_spec.rb +87 -0
  39. data/spec/cascading_configuration/core/module_spec.rb +491 -0
  40. data/spec/cascading_configuration/hash_spec.rb +826 -0
  41. data/spec/cascading_configuration/setting_spec.rb +687 -0
  42. data/spec/cascading_configuration_spec.rb +58 -0
  43. metadata +185 -0
@@ -0,0 +1,491 @@
1
+
2
+ require_relative '../../../lib/cascading_configuration.rb'
3
+
4
+ describe ::CascadingConfiguration::Core::Module do
5
+
6
+ ################
7
+ # initialize #
8
+ ################
9
+
10
+ it 'can initialize with a base name for a default encapsulation and with aliases' do
11
+ module ::CascadingConfiguration::Core::Module::InitializeMock
12
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
13
+ CCM = ::Module.new do
14
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
15
+ end
16
+ CCM::ClassInstance.default_encapsulation.should == ::CascadingConfiguration::Core::Module::DefaultEncapsulation
17
+ CCM::ClassInstance.ccm_name.should == :setting
18
+ CCM::ClassInstance.ccm_aliases.should == [ '' ]
19
+ end
20
+ end
21
+
22
+ ###########################
23
+ # cascading_method_name #
24
+ ###########################
25
+
26
+ it 'can return a cascading method name for a base name' do
27
+ module ::CascadingConfiguration::Core::Module::CascadingMethodNameMock
28
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
29
+ CCM = ::Module.new do
30
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
31
+ end
32
+ CCM::ClassInstance.module_eval do
33
+ cascading_method_name( 'some_name' ).should == 'attr_some_name'
34
+ end
35
+ end
36
+ end
37
+
38
+ ########################
39
+ # module_method_name #
40
+ ########################
41
+
42
+ it 'can return a module method name for a base name' do
43
+ module ::CascadingConfiguration::Core::Module::ModuleMethodNameMock
44
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
45
+ CCM = ::Module.new do
46
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
47
+ end
48
+ CCM::ClassInstance.module_eval do
49
+ module_method_name( 'some_name' ).should == 'attr_module_some_name'
50
+ end
51
+ end
52
+ end
53
+
54
+ #######################
55
+ # class_method_name #
56
+ #######################
57
+
58
+ it 'can return a class method name for a base name' do
59
+ module ::CascadingConfiguration::Core::Module::ClassMethodNameMock
60
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
61
+ CCM = ::Module.new do
62
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
63
+ end
64
+ CCM::ClassInstance.module_eval do
65
+ class_method_name( 'some_name' ).should == 'attr_class_some_name'
66
+ end
67
+ end
68
+ end
69
+
70
+ ##########################
71
+ # instance_method_name #
72
+ ##########################
73
+
74
+ it 'can return an instance method name for a base name' do
75
+ module ::CascadingConfiguration::Core::Module::InstanceMethodNameMock
76
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
77
+ CCM = ::Module.new do
78
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
79
+ end
80
+ CCM::ClassInstance.module_eval do
81
+ instance_method_name( 'some_name' ).should == 'attr_instance_some_name'
82
+ end
83
+ end
84
+ end
85
+
86
+ ################################
87
+ # local_method_name #
88
+ ################################
89
+
90
+ it 'can return a local instance method name for a base name' do
91
+ module ::CascadingConfiguration::Core::Module::LocalInstanceMethodNameMock
92
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
93
+ CCM = ::Module.new do
94
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
95
+ end
96
+ CCM::ClassInstance.module_eval do
97
+ local_instance_method_name( 'some_name' ).should == 'attr_local_some_name'
98
+ end
99
+ end
100
+ end
101
+
102
+ ########################
103
+ # object_method_name #
104
+ ########################
105
+
106
+ it 'can return an object method name for a base name' do
107
+ module ::CascadingConfiguration::Core::Module::ObjectMethodNameMock
108
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
109
+ CCM = ::Module.new do
110
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
111
+ end
112
+ CCM::ClassInstance.module_eval do
113
+ object_method_name( 'some_name' ).should == 'attr_object_some_name'
114
+ end
115
+ end
116
+ end
117
+
118
+ ##########################################
119
+ # define_method_with_extension_modules #
120
+ ##########################################
121
+
122
+ it 'can define cascading configuration methods' do
123
+ module ::CascadingConfiguration::Core::Module::DefineMethodWithExtensionModulesMock
124
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' ) do
125
+ def self.create_configuration( encapsulation, instance, name )
126
+ super
127
+ @called_create_configuration = true
128
+ end
129
+ def self.called_create_configuration?
130
+ returning_called_create_configuration = @called_create_configuration
131
+ @called_create_configuration = false
132
+ return returning_called_create_configuration
133
+ end
134
+ end
135
+ CCM = ::Module.new do
136
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
137
+ end
138
+ CCM::ClassInstance.module_eval do
139
+ # all
140
+ define_method_with_extension_modules( :all_base, [ :all_other ], :all )
141
+ method_defined?( :all_base ).should == true
142
+ method_defined?( :all_other ).should == true
143
+ method_defined?( :all_base_in ).should == true
144
+ method_defined?( :all_other_in ).should == true
145
+ instance_method( :all_base ).should == instance_method( :all_other )
146
+ instance_method( :all_base_in ).should == instance_method( :all_other_in )
147
+ # module
148
+ define_method_with_extension_modules( :module_base, [ :module_other ], :module )
149
+ method_defined?( :module_base ).should == true
150
+ method_defined?( :module_other ).should == true
151
+ method_defined?( :module_base_in ).should == true
152
+ method_defined?( :module_other_in ).should == true
153
+ instance_method( :module_base ).should == instance_method( :module_other )
154
+ instance_method( :module_base_in ).should == instance_method( :module_other_in )
155
+ # instance
156
+ define_method_with_extension_modules( :instance_base, [ :instance_other ], :instance )
157
+ method_defined?( :instance_base ).should == true
158
+ method_defined?( :instance_other ).should == true
159
+ method_defined?( :instance_base_in ).should == true
160
+ method_defined?( :instance_other_in ).should == true
161
+ instance_method( :instance_base ).should == instance_method( :instance_other )
162
+ instance_method( :instance_base_in ).should == instance_method( :instance_other_in )
163
+ # local_instance
164
+ define_method_with_extension_modules( :local_base, [ :local_other ], :local_instance )
165
+ method_defined?( :local_base ).should == true
166
+ method_defined?( :local_other ).should == true
167
+ method_defined?( :local_base_in ).should == true
168
+ method_defined?( :local_other_in ).should == true
169
+ instance_method( :local_base ).should == instance_method( :local_other )
170
+ instance_method( :local_base_in ).should == instance_method( :local_other_in )
171
+ # object
172
+ define_method_with_extension_modules( :object_base, [ :object_other ], :object )
173
+ method_defined?( :object_base ).should == true
174
+ method_defined?( :object_other ).should == true
175
+ method_defined?( :object_base_in ).should == true
176
+ method_defined?( :object_other_in ).should == true
177
+ instance_method( :object_other ).should == instance_method( :object_base )
178
+ instance_method( :object_other_in ).should == instance_method( :object_base_in )
179
+ end
180
+ module MethodTestMock
181
+
182
+ include CCM
183
+
184
+ # all
185
+ all_base( :all )
186
+
187
+ instance_methods.include?( :all ).should == true
188
+ respond_to?( :all ).should == true
189
+ CCM::ClassInstance.called_create_configuration?.should == true
190
+
191
+ # module
192
+ module_base( :module )
193
+ instance_methods.include?( :module ).should == false
194
+ respond_to?( :module ).should == true
195
+ CCM::ClassInstance.called_create_configuration?.should == true
196
+
197
+ # instance
198
+ instance_base( :instance )
199
+ instance_methods.include?( :instance ).should == true
200
+ respond_to?( :instance ).should == false
201
+ CCM::ClassInstance.called_create_configuration?.should == true
202
+
203
+ # local instance
204
+ local_base( :local_instance )
205
+ instance_methods.include?( :local_instance ).should == true
206
+ respond_to?( :local_instance ).should == true
207
+ CCM::ClassInstance.called_create_configuration?.should == true
208
+
209
+ # object
210
+ object_base( :object )
211
+ instance_methods.include?( :object ).should == false
212
+ respond_to?( :object ).should == true
213
+ CCM::ClassInstance.called_create_configuration?.should == true
214
+
215
+ end
216
+ end
217
+ end
218
+
219
+ ########################################
220
+ # define_cascading_definition_method #
221
+ ########################################
222
+
223
+ it 'can define cascading configuration methods that define cascading configurations' do
224
+ module ::CascadingConfiguration::Core::Module::DefineCascadingDefinitionMethodMock
225
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
226
+ CCM = ::Module.new do
227
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
228
+ end
229
+ CCM::ClassInstance.module_eval do
230
+
231
+ define_cascading_definition_method( :base, :other )
232
+
233
+ method_defined?( :attr_base ).should == true
234
+ method_defined?( :attr_other ).should == true
235
+ method_defined?( :attr_base_in ).should == true
236
+ method_defined?( :attr_other_in ).should == true
237
+ instance_method( :attr_base ).should == instance_method( :attr_other )
238
+ instance_method( :attr_base_in ).should == instance_method( :attr_other_in )
239
+
240
+ module MethodTestMock
241
+ include CCM
242
+ attr_base( :all )
243
+ instance_methods.include?( :all ).should == true
244
+ respond_to?( :all ).should == true
245
+ end
246
+ end
247
+ end
248
+ end
249
+
250
+ #####################################
251
+ # define_module_definition_method #
252
+ #####################################
253
+
254
+ it 'can define cascading configuration methods that define module configurations' do
255
+ module ::CascadingConfiguration::Core::Module::DefineModuleDefinitionMethodMock
256
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
257
+ CCM = ::Module.new do
258
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
259
+ end
260
+ CCM::ClassInstance.module_eval do
261
+
262
+ define_module_definition_method( :base, :other )
263
+
264
+ method_defined?( :attr_module_base ).should == true
265
+ method_defined?( :attr_module_other ).should == true
266
+ method_defined?( :attr_module_base_in ).should == true
267
+ method_defined?( :attr_module_other_in ).should == true
268
+ instance_method( :attr_module_base ).should == instance_method( :attr_module_other )
269
+ instance_method( :attr_module_base_in ).should == instance_method( :attr_module_other_in )
270
+
271
+ module MethodTestMock
272
+ include CCM
273
+ attr_module_base( :module )
274
+ instance_methods.include?( :module ).should == false
275
+ respond_to?( :module ).should == true
276
+ end
277
+ end
278
+ end
279
+ end
280
+
281
+ #######################################
282
+ # define_instance_definition_method #
283
+ #######################################
284
+
285
+ it 'can define cascading configuration methods that define instance configurations' do
286
+ module ::CascadingConfiguration::Core::Module::DefineInstanceDefinitionMethodMock
287
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
288
+ CCM = ::Module.new do
289
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
290
+ end
291
+ CCM::ClassInstance.module_eval do
292
+
293
+ define_instance_definition_method( :base, :other )
294
+
295
+ method_defined?( :attr_instance_base ).should == true
296
+ method_defined?( :attr_instance_other ).should == true
297
+ method_defined?( :attr_instance_base_in ).should == true
298
+ method_defined?( :attr_instance_other_in ).should == true
299
+ instance_method( :attr_instance_base ).should == instance_method( :attr_instance_other )
300
+ instance_method( :attr_instance_base_in ).should == instance_method( :attr_instance_other_in )
301
+
302
+ module MethodTestMock
303
+ include CCM
304
+ module InstanceModule
305
+ end
306
+ attr_instance_base( :instance )
307
+ instance_methods.include?( :instance ).should == true
308
+ respond_to?( :instance ).should == false
309
+ end
310
+ end
311
+ end
312
+ end
313
+
314
+ #############################################
315
+ # define_local_definition_method #
316
+ #############################################
317
+
318
+ it 'can define cascading configuration methods that define local configurations' do
319
+ module ::CascadingConfiguration::Core::Module::DefineLocalInstanceDefinitionMethodMock
320
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
321
+ CCM = ::Module.new do
322
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
323
+ end
324
+ CCM::ClassInstance.module_eval do
325
+
326
+ define_local_instance_definition_method( :base, :other )
327
+
328
+ method_defined?( :attr_local_base ).should == true
329
+ method_defined?( :attr_local_other ).should == true
330
+ method_defined?( :attr_local_base_in ).should == true
331
+ method_defined?( :attr_local_other_in ).should == true
332
+ instance_method( :attr_local_base ).should == instance_method( :attr_local_other )
333
+ instance_method( :attr_local_base_in ).should == instance_method( :attr_local_other_in )
334
+
335
+ module MethodTestMock
336
+ include CCM
337
+ module LocalInstanceModule
338
+ end
339
+ attr_local_base( :local_instance )
340
+ instance_methods.include?( :local_instance ).should == true
341
+ respond_to?( :local_instance ).should == true
342
+ end
343
+ end
344
+ end
345
+ end
346
+
347
+ #####################################
348
+ # define_object_definition_method #
349
+ #####################################
350
+
351
+ it 'can define cascading configuration methods that define object configurations' do
352
+ module ::CascadingConfiguration::Core::Module::DefineObjectDefinitionMethodMock
353
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
354
+ CCM = ::Module.new do
355
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
356
+ end
357
+ CCM::ClassInstance.module_eval do
358
+
359
+
360
+ define_object_definition_method( :base, :other )
361
+
362
+ method_defined?( :attr_object_base ).should == true
363
+ method_defined?( :attr_object_other ).should == true
364
+ method_defined?( :attr_object_base_in ).should == true
365
+ method_defined?( :attr_object_other_in ).should == true
366
+ instance_method( :attr_object_other ).should == instance_method( :attr_object_base )
367
+ instance_method( :attr_object_other_in ).should == instance_method( :attr_object_base_in )
368
+
369
+ module MethodTestMock
370
+ include CCM
371
+ module ObjectModule
372
+ end
373
+ attr_object_base( :object )
374
+ instance_methods.include?( :object ).should == false
375
+ respond_to?( :object ).should == true
376
+ end
377
+ end
378
+ end
379
+ end
380
+
381
+ ###############################
382
+ # define_definition_methods #
383
+ ###############################
384
+
385
+ it 'can define cascading configuration methods that define all types of cascading configuration methods' do
386
+ module ::CascadingConfiguration::Core::Module::DefineDefinitionMethodsMock
387
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
388
+ CCM = ::Module.new do
389
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
390
+ end
391
+ CCM::ClassInstance.module_eval do
392
+
393
+ define_definition_methods( :base, :other )
394
+
395
+ # all
396
+ method_defined?( :attr_base ).should == true
397
+ method_defined?( :attr_other ).should == true
398
+ method_defined?( :attr_base_in ).should == true
399
+ method_defined?( :attr_other_in ).should == true
400
+ instance_method( :attr_base ).should == instance_method( :attr_other )
401
+ instance_method( :attr_base_in ).should == instance_method( :attr_other_in )
402
+
403
+ # module
404
+ method_defined?( :attr_module_base ).should == true
405
+ method_defined?( :attr_module_other ).should == true
406
+ method_defined?( :attr_module_base_in ).should == true
407
+ method_defined?( :attr_module_other_in ).should == true
408
+ instance_method( :attr_module_base ).should == instance_method( :attr_module_other )
409
+ instance_method( :attr_module_base_in ).should == instance_method( :attr_module_other_in )
410
+
411
+ # instance
412
+ method_defined?( :attr_instance_base ).should == true
413
+ method_defined?( :attr_instance_other ).should == true
414
+ method_defined?( :attr_instance_base_in ).should == true
415
+ method_defined?( :attr_instance_other_in ).should == true
416
+ instance_method( :attr_instance_base ).should == instance_method( :attr_instance_other )
417
+ instance_method( :attr_instance_base_in ).should == instance_method( :attr_instance_other_in )
418
+
419
+ # local instance
420
+ method_defined?( :attr_local_base ).should == true
421
+ method_defined?( :attr_local_other ).should == true
422
+ method_defined?( :attr_local_base_in ).should == true
423
+ method_defined?( :attr_local_other_in ).should == true
424
+ instance_method( :attr_local_base ).should == instance_method( :attr_local_other )
425
+ instance_method( :attr_local_base_in ).should == instance_method( :attr_local_other_in )
426
+
427
+ # object
428
+ method_defined?( :attr_object_base ).should == true
429
+ method_defined?( :attr_object_other ).should == true
430
+ method_defined?( :attr_object_base_in ).should == true
431
+ method_defined?( :attr_object_other_in ).should == true
432
+ instance_method( :attr_object_other ).should == instance_method( :attr_object_base )
433
+ instance_method( :attr_object_other_in ).should == instance_method( :attr_object_base_in )
434
+
435
+ module MethodTestMock
436
+ include CCM
437
+
438
+ # all
439
+ attr_base( :all ) do
440
+ end
441
+ instance_methods.include?( :all ).should == true
442
+ respond_to?( :all ).should == true
443
+
444
+ # module
445
+ attr_module_base( :module ) do
446
+ end
447
+ instance_methods.include?( :module ).should == false
448
+ respond_to?( :module ).should == true
449
+
450
+ # instance
451
+ attr_instance_base( :instance ) do
452
+ end
453
+ instance_methods.include?( :instance ).should == true
454
+ respond_to?( :instance ).should == false
455
+
456
+ # local instance
457
+ attr_local_base( :local_instance ) do
458
+ end
459
+ instance_methods.include?( :local_instance ).should == true
460
+ respond_to?( :local_instance ).should == true
461
+
462
+ # object
463
+ attr_object_base( :object ) do
464
+ end
465
+ instance_methods.include?( :object ).should == false
466
+ respond_to?( :object ).should == true
467
+ end
468
+
469
+ end
470
+ end
471
+ end
472
+
473
+ ##########################
474
+ # create_configuration #
475
+ ##########################
476
+
477
+ it 'can create configurations for instances' do
478
+ module ::CascadingConfiguration::Core::Module::CreateConfigurationMock
479
+ ForInstance = ::Module.new
480
+ InstanceController = ::CascadingConfiguration::Core::InstanceController.new( ForInstance )
481
+ Encapsulation = ::CascadingConfiguration::Core::Module::DefaultEncapsulation
482
+ ClassInstance = ::CascadingConfiguration::Core::Module.new( :setting, :default, '' )
483
+ CCM = ::Module.new do
484
+ ::CascadingConfiguration::Core.enable( self, ClassInstance )
485
+ end
486
+ CCM::ClassInstance.create_configuration( Encapsulation, ForInstance, :some_configuration )
487
+ Encapsulation.has_configuration?( ForInstance, :some_configuration ).should == true
488
+ end
489
+ end
490
+
491
+ end