module-cluster 1.4.8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.md +127 -337
  2. data/lib/module-cluster.rb +1 -153
  3. data/lib/module/cluster.rb +341 -0
  4. data/lib/module/cluster/class_support.rb +22 -0
  5. data/lib/module/cluster/cluster.rb +10 -0
  6. data/lib/module/cluster/cluster/cluster_interface.rb +550 -0
  7. data/lib/module/cluster/exception/module_not_in_stack.rb +26 -0
  8. data/lib/module/cluster/instance_controller.rb +14 -0
  9. data/lib/module/cluster/instance_controller/hook_controller.rb +33 -0
  10. data/lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb +511 -0
  11. data/lib/module/cluster/instance_controller/hook_controller/hook_controller_interface.rb +830 -0
  12. data/lib/module/cluster/instance_controller/instance_controller_interface.rb +269 -0
  13. data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy.rb +359 -0
  14. data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy/chain_proxy.rb +442 -0
  15. data/lib/module/cluster/module_support.rb +67 -0
  16. data/lib/module/namespaces.rb +13 -0
  17. data/lib/module/requires.rb +32 -0
  18. data/spec/module/cluster/cluster_spec.rb +473 -0
  19. data/spec/module/cluster/instance_controller/hook_controller_spec.rb +922 -0
  20. data/spec/module/cluster/instance_controller/multiple_hook_controller_proxy_spec.rb +1240 -0
  21. data/spec/module/cluster_spec.rb +1794 -0
  22. metadata +27 -98
  23. data/README.rdoc +0 -395
  24. data/lib/module-cluster/ModuleCluster.rb +0 -9
  25. data/lib/module-cluster/ModuleCluster/Define.rb +0 -12
  26. data/lib/module-cluster/ModuleCluster/Define/Block.rb +0 -9
  27. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingClass.rb +0 -83
  28. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingClassOrModule.rb +0 -70
  29. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingModule.rb +0 -79
  30. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingModuleOrSubclass.rb +0 -21
  31. data/lib/module-cluster/ModuleCluster/Define/Block/Class.rb +0 -77
  32. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb +0 -78
  33. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModule.rb +0 -78
  34. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrInstance.rb +0 -78
  35. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrSubclass.rb +0 -36
  36. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrSubclass.rb +0 -29
  37. data/lib/module-cluster/ModuleCluster/Define/Block/Instance.rb +0 -45
  38. data/lib/module-cluster/ModuleCluster/Define/Block/Module.rb +0 -77
  39. data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb +0 -78
  40. data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrSubclass.rb +0 -29
  41. data/lib/module-cluster/ModuleCluster/Define/Block/Subclass.rb +0 -56
  42. data/lib/module-cluster/ModuleCluster/Define/ClassCluster.rb +0 -193
  43. data/lib/module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb +0 -128
  44. data/lib/module-cluster/ModuleCluster/Define/Cluster.rb +0 -181
  45. data/lib/module-cluster/ModuleCluster/Define/ClusterCascades.rb +0 -185
  46. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb +0 -181
  47. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb +0 -181
  48. data/lib/module-cluster/ModuleCluster/Define/Deprecated.rb +0 -40
  49. data/lib/module-cluster/ModuleCluster/Define/InstanceCluster.rb +0 -45
  50. data/lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb +0 -193
  51. data/lib/module-cluster/ModuleCluster/Define/ModuleOrClassCluster.rb +0 -209
  52. data/lib/module-cluster/ModuleCluster/Define/ModuleOrInstanceCluster.rb +0 -128
  53. data/lib/module-cluster/ModuleCluster/Define/Status.rb +0 -106
  54. data/lib/module-cluster/ModuleCluster/Suspend.rb +0 -7
  55. data/lib/module-cluster/ModuleCluster/Suspend/Hooks.rb +0 -315
  56. data/lib/module-cluster/ModuleCluster/Suspend/WithoutHooks.rb +0 -153
  57. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures.rb +0 -77
  58. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb +0 -44
  59. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb +0 -292
  60. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclass.rb +0 -24
  61. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack.rb +0 -12
  62. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block.rb +0 -9
  63. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb +0 -36
  64. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Inherited.rb +0 -20
  65. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb +0 -20
  66. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb +0 -36
  67. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb +0 -6
  68. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb +0 -140
  69. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Includes.rb +0 -110
  70. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb +0 -140
  71. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb +0 -110
  72. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb +0 -35
  73. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy.rb +0 -359
  74. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Status.rb +0 -55
  75. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Suspend.rb +0 -199
  76. data/lib/module-cluster/_private_/ModuleCluster/ExtendForCascade.rb +0 -34
  77. data/spec/ModuleCluster/Define/Block/CascadingClassOrModule_spec.rb +0 -285
  78. data/spec/ModuleCluster/Define/Block/CascadingClass_spec.rb +0 -254
  79. data/spec/ModuleCluster/Define/Block/CascadingModuleOrSubclass_spec.rb +0 -56
  80. data/spec/ModuleCluster/Define/Block/CascadingModule_spec.rb +0 -278
  81. data/spec/ModuleCluster/Define/Block/ClassOrInstance_spec.rb +0 -230
  82. data/spec/ModuleCluster/Define/Block/ClassOrModuleOrInstance_spec.rb +0 -238
  83. data/spec/ModuleCluster/Define/Block/ClassOrModuleOrSubclass_spec.rb +0 -54
  84. data/spec/ModuleCluster/Define/Block/ClassOrModule_spec.rb +0 -231
  85. data/spec/ModuleCluster/Define/Block/ClassOrSubclass_spec.rb +0 -54
  86. data/spec/ModuleCluster/Define/Block/Class_spec.rb +0 -224
  87. data/spec/ModuleCluster/Define/Block/Instance_spec.rb +0 -78
  88. data/spec/ModuleCluster/Define/Block/ModuleOrInstance_spec.rb +0 -54
  89. data/spec/ModuleCluster/Define/Block/ModuleOrSubclass_spec.rb +0 -51
  90. data/spec/ModuleCluster/Define/Block/Module_spec.rb +0 -230
  91. data/spec/ModuleCluster/Define/Block/Subclass_spec.rb +0 -73
  92. data/spec/ModuleCluster/Define/Block_spec.rb +0 -18
  93. data/spec/ModuleCluster/Define/ClassCluster_spec.rb +0 -728
  94. data/spec/ModuleCluster/Define/ClassOrInstanceCluster_spec.rb +0 -576
  95. data/spec/ModuleCluster/Define/ClusterCascadesToClass_spec.rb +0 -659
  96. data/spec/ModuleCluster/Define/ClusterCascadesToModule_spec.rb +0 -678
  97. data/spec/ModuleCluster/Define/ClusterCascades_spec.rb +0 -644
  98. data/spec/ModuleCluster/Define/Cluster_spec.rb +0 -708
  99. data/spec/ModuleCluster/Define/InstanceCluster_spec.rb +0 -102
  100. data/spec/ModuleCluster/Define/ModuleCluster_spec.rb +0 -728
  101. data/spec/ModuleCluster/Define/ModuleOrClassCluster_spec.rb +0 -728
  102. data/spec/ModuleCluster/Define/ModuleOrInstanceCluster_spec.rb +0 -576
  103. data/spec/ModuleCluster/Suspend/Hooks_spec.rb +0 -573
  104. data/spec/ModuleCluster/Suspend/WithoutHooks_spec.rb +0 -559
  105. data/spec/ModuleCluster_spec.rb +0 -15
  106. data/spec/_private_/ModuleCluster/CascadeFeatures/PerformCascades_spec.rb +0 -386
  107. data/spec/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy_spec.rb +0 -419
  108. data/spec/_private_/ModuleCluster/ClusterStack/Suspend_spec.rb +0 -242
@@ -0,0 +1,1794 @@
1
+
2
+ require_relative '../../lib/module/cluster.rb'
3
+
4
+ describe ::Module::Cluster do
5
+
6
+ ####################
7
+ # named clusters #
8
+ ####################
9
+
10
+ it 'can create named clusters' do
11
+ module ::Module::Cluster::NamedClusterMock
12
+
13
+ module ClusterModuleMock
14
+
15
+ extend ::Module::Cluster
16
+
17
+ new_cluster_set = cluster( :cluster_name )
18
+ new_cluster_set.is_a?( ::Module::Cluster::Cluster ).should == true
19
+ cluster( :cluster_name ).should == new_cluster_set
20
+
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ ###################
27
+ # include hooks #
28
+ ###################
29
+
30
+ # before - without block
31
+
32
+ it 'can create before-include hooks' do
33
+ module ::Module::Cluster::BeforeIncludeHookMock
34
+
35
+ module A
36
+ end
37
+
38
+ module ClusterModuleMock
39
+ extend ::Module::Cluster
40
+ cluster( :cluster_name ).before_include.extend( A )
41
+ def self.included( instance )
42
+ instance.is_a?( A ).should == true
43
+ super if defined?( super )
44
+ end
45
+ end
46
+
47
+ module AnotherModule
48
+ include ClusterModuleMock
49
+ is_a?( A ).should == true
50
+ end
51
+
52
+ module OtherModule
53
+ include AnotherModule
54
+ is_a?( A ).should == false
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ # after - without block
61
+
62
+ it 'can create after-include hooks' do
63
+ module ::Module::Cluster::AfterIncludeHookMock
64
+
65
+ module A
66
+ end
67
+
68
+ module ClusterModuleMock
69
+ extend ::Module::Cluster
70
+ cluster( :cluster_name ).after_include.extend( A )
71
+ def self.included( instance )
72
+ instance.is_a?( A ).should == false
73
+ super if defined?( super )
74
+ end
75
+ end
76
+
77
+ module AnotherModule
78
+ include ClusterModuleMock
79
+ is_a?( A ).should == true
80
+ end
81
+
82
+ module OtherModule
83
+ include AnotherModule
84
+ is_a?( A ).should == false
85
+ end
86
+
87
+ end
88
+ end
89
+
90
+ # before - with block
91
+
92
+ it 'can create before-include hooks with block events' do
93
+ module ::Module::Cluster::BeforeIncludeHookBlockMock
94
+
95
+ module A
96
+ end
97
+
98
+ ClusterModuleMock = ::Module.new
99
+
100
+ block_ran = false
101
+
102
+ ClusterModuleMock.module_eval do
103
+ extend ::Module::Cluster
104
+ block = ::Proc.new do |instance|
105
+ instance.is_a?( A ).should == true
106
+ block_ran = true
107
+ end
108
+ cluster( :cluster_name ).before_include.extend( A, & block )
109
+ def self.included( instance )
110
+ instance.is_a?( A ).should == true
111
+ super if defined?( super )
112
+ end
113
+ end
114
+
115
+ module AnotherModule
116
+ include ClusterModuleMock
117
+ is_a?( A ).should == true
118
+ end
119
+
120
+ block_ran.should == true
121
+
122
+ block_ran = false
123
+
124
+ module OtherModule
125
+ include AnotherModule
126
+ is_a?( A ).should == false
127
+ end
128
+
129
+ block_ran.should == false
130
+
131
+ end
132
+ end
133
+
134
+ # after - with block
135
+
136
+ it 'can create after-include hooks with block events' do
137
+ module ::Module::Cluster::AfterIncludeHookBlockMock
138
+
139
+ module A
140
+ end
141
+
142
+ ClusterModuleMock = ::Module.new
143
+
144
+ block_ran = false
145
+
146
+ ClusterModuleMock.module_eval do
147
+ extend ::Module::Cluster
148
+ block = ::Proc.new do |instance|
149
+ instance.is_a?( A ).should == true
150
+ block_ran = true
151
+ end
152
+ cluster( :cluster_name ).after_include.extend( A, & block )
153
+ def self.included( instance )
154
+ instance.is_a?( A ).should == false
155
+ super if defined?( super )
156
+ end
157
+ end
158
+
159
+ module AnotherModule
160
+ include ClusterModuleMock
161
+ is_a?( A ).should == true
162
+ end
163
+
164
+ block_ran.should == true
165
+
166
+ block_ran = false
167
+
168
+ module OtherModule
169
+ include AnotherModule
170
+ is_a?( A ).should == false
171
+ end
172
+
173
+ block_ran.should == false
174
+
175
+ end
176
+ end
177
+
178
+ ##################
179
+ # extend hooks #
180
+ ##################
181
+
182
+ # before - without block
183
+
184
+ it 'can create before-extend hooks' do
185
+ module ::Module::Cluster::BeforeExtendHookMock
186
+
187
+ module A
188
+ end
189
+
190
+ module ClusterModuleMock
191
+ extend ::Module::Cluster
192
+ cluster( :cluster_name ).before_extend.extend( A )
193
+ def self.extended( instance )
194
+ instance.is_a?( A ).should == true
195
+ super if defined?( super )
196
+ end
197
+ end
198
+
199
+ module AnotherModule
200
+ extend ClusterModuleMock
201
+ is_a?( A ).should == true
202
+ end
203
+
204
+ module OtherModule
205
+ extend AnotherModule
206
+ is_a?( A ).should == false
207
+ end
208
+
209
+ end
210
+ end
211
+
212
+ # after - without block
213
+
214
+ it 'can create after-extend hooks' do
215
+ module ::Module::Cluster::AfterExtendHookMock
216
+
217
+ module A
218
+ end
219
+
220
+ module ClusterModuleMock
221
+ extend ::Module::Cluster
222
+ cluster( :cluster_name ).after_extend.extend( A )
223
+ def self.extended( instance )
224
+ instance.is_a?( A ).should == false
225
+ super if defined?( super )
226
+ end
227
+ end
228
+
229
+ module AnotherModule
230
+ extend ClusterModuleMock
231
+ is_a?( A ).should == true
232
+ end
233
+
234
+ module OtherModule
235
+ extend AnotherModule
236
+ is_a?( A ).should == false
237
+ end
238
+
239
+ end
240
+ end
241
+
242
+ # before - with block
243
+
244
+ it 'can create extend hooks with block events' do
245
+ module ::Module::Cluster::BeforeExtendHookBlockMock
246
+
247
+ module A
248
+ end
249
+
250
+ ClusterModuleMock = ::Module.new
251
+
252
+ block_ran = false
253
+
254
+ ClusterModuleMock.module_eval do
255
+ extend ::Module::Cluster
256
+ block = ::Proc.new do |instance|
257
+ instance.is_a?( A ).should == true
258
+ block_ran = true
259
+ end
260
+ cluster( :cluster_name ).before_extend.extend( A, & block )
261
+ def self.extended( instance )
262
+ instance.is_a?( A ).should == true
263
+ super if defined?( super )
264
+ end
265
+ end
266
+
267
+ module AnotherModule
268
+ extend ClusterModuleMock
269
+ is_a?( A ).should == true
270
+ end
271
+
272
+ block_ran.should == true
273
+
274
+ block_ran = false
275
+
276
+ module OtherModule
277
+ extend AnotherModule
278
+ is_a?( A ).should == false
279
+ end
280
+
281
+ block_ran.should == false
282
+
283
+ end
284
+ end
285
+
286
+ # after - with block
287
+
288
+ it 'can create extend hooks with block events' do
289
+ module ::Module::Cluster::AfterExtendHookBlockMock
290
+
291
+ module A
292
+ end
293
+
294
+ ClusterModuleMock = ::Module.new
295
+
296
+ block_ran = false
297
+
298
+ ClusterModuleMock.module_eval do
299
+ extend ::Module::Cluster
300
+ block = ::Proc.new do |instance|
301
+ instance.is_a?( A ).should == true
302
+ block_ran = true
303
+ end
304
+ cluster( :cluster_name ).after_extend.extend( A, & block )
305
+ def self.extended( instance )
306
+ instance.is_a?( A ).should == false
307
+ super if defined?( super )
308
+ end
309
+ end
310
+
311
+ module AnotherModule
312
+ extend ClusterModuleMock
313
+ is_a?( A ).should == true
314
+ end
315
+
316
+ block_ran.should == true
317
+
318
+ block_ran = false
319
+
320
+ module OtherModule
321
+ extend AnotherModule
322
+ is_a?( A ).should == false
323
+ end
324
+
325
+ block_ran.should == false
326
+
327
+ end
328
+ end
329
+
330
+ ####################
331
+ # subclass hooks #
332
+ ####################
333
+
334
+ # class - without block
335
+
336
+ it 'can create subclass hooks with block events' do
337
+ module ::Module::Cluster::SubclassClassHookMock
338
+
339
+ module A
340
+ end
341
+
342
+ class ClusterClassMock
343
+ extend ::Module::Cluster
344
+ cluster( :cluster_name ).subclass.extend( A )
345
+ def self.inherited( instance )
346
+ instance.is_a?( A ).should == false
347
+ super if defined?( super )
348
+ instance.is_a?( A ).should == true
349
+ end
350
+ end
351
+
352
+ class AnotherClass < ClusterClassMock
353
+ is_a?( A ).should == true
354
+ end
355
+
356
+ end
357
+ end
358
+
359
+ # class - with block
360
+
361
+ it 'can create subclass hooks with block events' do
362
+ module ::Module::Cluster::SubclassClassHookBlockMock
363
+
364
+ module A
365
+ end
366
+
367
+ block_ran = false
368
+
369
+ ClusterClassMock = ::Class.new
370
+ ClusterClassMock.class_eval do
371
+ extend ::Module::Cluster
372
+ block = ::Proc.new do |instance|
373
+ block_ran = true
374
+ instance.is_a?( A ).should == true
375
+ end
376
+ cluster( :cluster_name ).subclass.extend( A, & block )
377
+ def self.inherited( instance )
378
+ instance.is_a?( A ).should == false
379
+ super if defined?( super )
380
+ instance.is_a?( A ).should == true
381
+ end
382
+ end
383
+
384
+ class AnotherClass < ClusterClassMock
385
+ is_a?( A ).should == true
386
+ end
387
+
388
+ block_ran.should == true
389
+
390
+ end
391
+ end
392
+
393
+ # module - without block
394
+
395
+ it 'can create subclass hooks with block events' do
396
+ module ::Module::Cluster::SubclassModuleHookMock
397
+
398
+ module A
399
+ end
400
+
401
+ module ClusterModuleMock
402
+ extend ::Module::Cluster
403
+ cluster( :cluster_name ).subclass.extend( A )
404
+ end
405
+
406
+ class BaseClassA
407
+ include ClusterModuleMock
408
+ def self.inherited( instance )
409
+ instance.is_a?( A ).should == false
410
+ super if defined?( super )
411
+ instance.is_a?( A ).should == true
412
+ end
413
+ end
414
+
415
+ class BaseClassB
416
+ extend ClusterModuleMock
417
+ def self.inherited( instance )
418
+ instance.is_a?( A ).should == false
419
+ super if defined?( super )
420
+ instance.is_a?( A ).should == true
421
+ end
422
+ end
423
+
424
+ class ClassA < BaseClassA
425
+ is_a?( A ).should == true
426
+ end
427
+
428
+ class ClassB < BaseClassB
429
+ is_a?( A ).should == true
430
+ end
431
+
432
+ end
433
+ end
434
+
435
+ # module - with block
436
+
437
+ it 'can create subclass hooks with block events' do
438
+ module ::Module::Cluster::SubclassModuleHookBlockMock
439
+
440
+ module A
441
+ end
442
+
443
+ block_ran = false
444
+
445
+ ClusterModuleMock = ::Module.new
446
+ ClusterModuleMock.module_eval do
447
+ extend ::Module::Cluster
448
+ block = ::Proc.new do |instance|
449
+ instance.is_a?( A ).should == true
450
+ block_ran = true
451
+ end
452
+ cluster( :cluster_name ).subclass.extend( A, & block )
453
+ end
454
+
455
+ class BaseClassA
456
+ include ClusterModuleMock
457
+ def self.inherited( instance )
458
+ instance.is_a?( A ).should == false
459
+ super if defined?( super )
460
+ instance.is_a?( A ).should == true
461
+ end
462
+ end
463
+
464
+ class BaseClassB
465
+ extend ClusterModuleMock
466
+ def self.inherited( instance )
467
+ instance.is_a?( A ).should == false
468
+ super if defined?( super )
469
+ instance.is_a?( A ).should == true
470
+ end
471
+ end
472
+
473
+ block_ran.should == false
474
+
475
+ class ClassA < BaseClassA
476
+ is_a?( A ).should == true
477
+ end
478
+
479
+ block_ran.should == true
480
+
481
+ block_ran = false
482
+
483
+ class ClassB < BaseClassB
484
+ is_a?( A ).should == true
485
+ end
486
+
487
+ block_ran.should == true
488
+
489
+ end
490
+ end
491
+
492
+ #######################
493
+ # conditional hooks #
494
+ #######################
495
+
496
+ # class - before
497
+
498
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
499
+ module ::Module::Cluster::BeforeClassConditionalHookMock
500
+
501
+ module A
502
+ end
503
+ module B
504
+ end
505
+ module C
506
+ end
507
+
508
+ module ClusterModuleMock
509
+
510
+ extend ::Module::Cluster
511
+
512
+ cluster( :cluster_name ).before_include( :class ).extend( A )
513
+ cluster( :cluster_name ).before_extend( :class ).extend( B )
514
+ cluster( :cluster_name ).before_include_or_extend( :class ).extend( C )
515
+
516
+ end
517
+
518
+ module IncludeModuleMock
519
+ include ClusterModuleMock
520
+ is_a?( A ).should == false
521
+ is_a?( C ).should == false
522
+ end
523
+
524
+ module ExtendModuleMock
525
+ extend ClusterModuleMock
526
+ is_a?( B ).should == false
527
+ is_a?( C ).should == false
528
+ end
529
+
530
+ class IncludeClassMock
531
+ include ClusterModuleMock
532
+ is_a?( A ).should == true
533
+ is_a?( C ).should == true
534
+ eigenclass = class << self ; self ;end
535
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
536
+ end
537
+
538
+ class ExtendClassMock
539
+ extend ClusterModuleMock
540
+ is_a?( B ).should == true
541
+ is_a?( C ).should == true
542
+ eigenclass = class << self ; self ;end
543
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
544
+ end
545
+
546
+ instance = Object.new
547
+ instance.extend( ClusterModuleMock )
548
+ instance.is_a?( A ).should == false
549
+ instance.is_a?( B ).should == false
550
+ instance.is_a?( C ).should == false
551
+
552
+ end
553
+ end
554
+
555
+ # class - after
556
+
557
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
558
+ module ::Module::Cluster::AfterClassConditionalHookMock
559
+
560
+ module A
561
+ end
562
+ module B
563
+ end
564
+ module C
565
+ end
566
+
567
+ module ClusterModuleMock
568
+
569
+ extend ::Module::Cluster
570
+
571
+ cluster( :cluster_name ).after_include( :class ).extend( A )
572
+ cluster( :cluster_name ).after_extend( :class ).extend( B )
573
+ cluster( :cluster_name ).after_include_or_extend( :class ).extend( C )
574
+
575
+ end
576
+
577
+ module IncludeModuleMock
578
+ include ClusterModuleMock
579
+ is_a?( A ).should == false
580
+ is_a?( C ).should == false
581
+ end
582
+
583
+ module ExtendModuleMock
584
+ extend ClusterModuleMock
585
+ is_a?( B ).should == false
586
+ is_a?( C ).should == false
587
+ end
588
+
589
+ class IncludeClassMock
590
+ include ClusterModuleMock
591
+ is_a?( A ).should == true
592
+ is_a?( C ).should == true
593
+ eigenclass = class << self ; self ;end
594
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
595
+ end
596
+
597
+ class ExtendClassMock
598
+ extend ClusterModuleMock
599
+ is_a?( B ).should == true
600
+ is_a?( C ).should == true
601
+ eigenclass = class << self ; self ;end
602
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
603
+ end
604
+
605
+ instance = Object.new
606
+ instance.extend( ClusterModuleMock )
607
+ instance.is_a?( A ).should == false
608
+ instance.is_a?( B ).should == false
609
+ instance.is_a?( C ).should == false
610
+
611
+ end
612
+ end
613
+
614
+ # module
615
+
616
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
617
+ module ::Module::Cluster::BeforeModuleConditionalHookMock
618
+
619
+ module A
620
+ end
621
+ module B
622
+ end
623
+ module C
624
+ end
625
+
626
+ module ClusterModuleMock
627
+
628
+ extend ::Module::Cluster
629
+
630
+ cluster( :cluster_name ).before_include( :module ).extend( A )
631
+ cluster( :cluster_name ).before_extend( :module ).extend( B )
632
+ cluster( :cluster_name ).before_include_or_extend( :module ).extend( C )
633
+
634
+ end
635
+
636
+ module IncludeModuleMock
637
+ include ClusterModuleMock
638
+ is_a?( A ).should == true
639
+ is_a?( C ).should == true
640
+ eigenclass = class << self ; self ;end
641
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
642
+ end
643
+
644
+ module ExtendModuleMock
645
+ extend ClusterModuleMock
646
+ is_a?( B ).should == true
647
+ is_a?( C ).should == true
648
+ eigenclass = class << self ; self ;end
649
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
650
+ end
651
+
652
+ class IncludeClassMock
653
+ include ClusterModuleMock
654
+ is_a?( A ).should == false
655
+ is_a?( C ).should == false
656
+ end
657
+
658
+ class ExtendClassMock
659
+ extend ClusterModuleMock
660
+ is_a?( B ).should == false
661
+ is_a?( C ).should == false
662
+ end
663
+
664
+ instance = Object.new
665
+ instance.extend( ClusterModuleMock )
666
+ instance.is_a?( A ).should == false
667
+ instance.is_a?( B ).should == false
668
+ instance.is_a?( C ).should == false
669
+
670
+ end
671
+ end
672
+
673
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
674
+ module ::Module::Cluster::AfterModuleConditionalHookMock
675
+
676
+ module A
677
+ end
678
+ module B
679
+ end
680
+ module C
681
+ end
682
+
683
+ module ClusterModuleMock
684
+
685
+ extend ::Module::Cluster
686
+
687
+ cluster( :cluster_name ).after_include( :module ).extend( A )
688
+ cluster( :cluster_name ).after_extend( :module ).extend( B )
689
+ cluster( :cluster_name ).after_include_or_extend( :module ).extend( C )
690
+
691
+ end
692
+
693
+ module IncludeModuleMock
694
+ include ClusterModuleMock
695
+ is_a?( A ).should == true
696
+ is_a?( C ).should == true
697
+ eigenclass = class << self ; self ;end
698
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
699
+ end
700
+
701
+ module ExtendModuleMock
702
+ extend ClusterModuleMock
703
+ is_a?( B ).should == true
704
+ is_a?( C ).should == true
705
+ eigenclass = class << self ; self ;end
706
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
707
+ end
708
+
709
+ class IncludeClassMock
710
+ include ClusterModuleMock
711
+ is_a?( A ).should == false
712
+ is_a?( C ).should == false
713
+ end
714
+
715
+ class ExtendClassMock
716
+ extend ClusterModuleMock
717
+ is_a?( B ).should == false
718
+ is_a?( C ).should == false
719
+ end
720
+
721
+ instance = Object.new
722
+ instance.extend( ClusterModuleMock )
723
+ instance.is_a?( A ).should == false
724
+ instance.is_a?( B ).should == false
725
+ instance.is_a?( C ).should == false
726
+
727
+ end
728
+ end
729
+
730
+ # instance
731
+
732
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
733
+ module ::Module::Cluster::BeforeInstanceConditionalHookMock
734
+
735
+ module A
736
+ end
737
+ module B
738
+ end
739
+ module C
740
+ end
741
+
742
+ module ClusterModuleMock
743
+
744
+ extend ::Module::Cluster
745
+
746
+ # meaningless
747
+ cluster( :cluster_name ).before_include( :instance ).extend( A )
748
+ cluster( :cluster_name ).before_extend( :instance ).extend( B )
749
+ # meaningless for include - really just doubles for extend
750
+ cluster( :cluster_name ).before_include_or_extend( :instance ).extend( C )
751
+
752
+ end
753
+
754
+ module IncludeModuleMock
755
+ include ClusterModuleMock
756
+ is_a?( B ).should == false
757
+ is_a?( C ).should == false
758
+ end
759
+
760
+ module ExtendModuleMock
761
+ extend ClusterModuleMock
762
+ is_a?( B ).should == false
763
+ is_a?( C ).should == false
764
+ end
765
+
766
+ class IncludeClassMock
767
+ include ClusterModuleMock
768
+ is_a?( A ).should == false
769
+ is_a?( C ).should == false
770
+ end
771
+
772
+ class ExtendClassMock
773
+ extend ClusterModuleMock
774
+ is_a?( B ).should == false
775
+ is_a?( C ).should == false
776
+ end
777
+
778
+ instance = Object.new
779
+ instance.extend( ClusterModuleMock )
780
+ instance.is_a?( A ).should == false
781
+ instance.is_a?( B ).should == true
782
+ instance.is_a?( C ).should == true
783
+ eigenclass = class << instance ; self ;end
784
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
785
+
786
+ end
787
+ end
788
+
789
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
790
+ module ::Module::Cluster::AfterInstanceConditionalHookMock
791
+
792
+ module A
793
+ end
794
+ module B
795
+ end
796
+ module C
797
+ end
798
+
799
+ module ClusterModuleMock
800
+
801
+ extend ::Module::Cluster
802
+
803
+ # meaningless
804
+ cluster( :cluster_name ).after_include( :instance ).extend( A )
805
+ cluster( :cluster_name ).after_extend( :instance ).extend( B )
806
+ # meaningless for include - really just doubles for extend
807
+ cluster( :cluster_name ).after_include_or_extend( :instance ).extend( C )
808
+
809
+ end
810
+
811
+ module IncludeModuleMock
812
+ include ClusterModuleMock
813
+ is_a?( B ).should == false
814
+ is_a?( C ).should == false
815
+ end
816
+
817
+ module ExtendModuleMock
818
+ extend ClusterModuleMock
819
+ is_a?( B ).should == false
820
+ is_a?( C ).should == false
821
+ end
822
+
823
+ class IncludeClassMock
824
+ include ClusterModuleMock
825
+ is_a?( A ).should == false
826
+ is_a?( C ).should == false
827
+ end
828
+
829
+ class ExtendClassMock
830
+ extend ClusterModuleMock
831
+ is_a?( B ).should == false
832
+ is_a?( C ).should == false
833
+ end
834
+
835
+ instance = Object.new
836
+ instance.extend( ClusterModuleMock )
837
+ instance.is_a?( B ).should == true
838
+ instance.is_a?( C ).should == true
839
+ eigenclass = class << instance ; self ;end
840
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
841
+
842
+ end
843
+ end
844
+
845
+ # class or module
846
+
847
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
848
+ module ::Module::Cluster::BeforeClassModuleConditionalHookMock
849
+
850
+ module A
851
+ end
852
+ module B
853
+ end
854
+ module C
855
+ end
856
+
857
+ module ClusterModuleMock
858
+
859
+ extend ::Module::Cluster
860
+
861
+ cluster( :cluster_name ).before_include( :class, :module ).extend( A )
862
+ cluster( :cluster_name ).before_extend( :class, :module ).extend( B )
863
+ cluster( :cluster_name ).before_include_or_extend( :class, :module ).extend( C )
864
+
865
+ end
866
+
867
+ module IncludeModuleMock
868
+ include ClusterModuleMock
869
+ is_a?( A ).should == true
870
+ is_a?( C ).should == true
871
+ eigenclass = class << self ; self ;end
872
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
873
+ end
874
+
875
+ module ExtendModuleMock
876
+ extend ClusterModuleMock
877
+ is_a?( B ).should == true
878
+ is_a?( C ).should == true
879
+ eigenclass = class << self ; self ;end
880
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
881
+ end
882
+
883
+ class IncludeClassMock
884
+ include ClusterModuleMock
885
+ is_a?( A ).should == true
886
+ is_a?( C ).should == true
887
+ eigenclass = class << self ; self ;end
888
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
889
+ end
890
+
891
+ class ExtendClassMock
892
+ extend ClusterModuleMock
893
+ is_a?( B ).should == true
894
+ is_a?( C ).should == true
895
+ eigenclass = class << self ; self ;end
896
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
897
+ end
898
+
899
+ instance = Object.new
900
+ instance.extend( ClusterModuleMock )
901
+ instance.is_a?( A ).should == false
902
+ instance.is_a?( B ).should == false
903
+ instance.is_a?( C ).should == false
904
+
905
+ end
906
+ end
907
+
908
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
909
+ module ::Module::Cluster::AfterClassModuleConditionalHookMock
910
+
911
+ module A
912
+ end
913
+ module B
914
+ end
915
+ module C
916
+ end
917
+
918
+ module ClusterModuleMock
919
+
920
+ extend ::Module::Cluster
921
+
922
+ cluster( :cluster_name ).after_include( :class, :module ).extend( A )
923
+ cluster( :cluster_name ).after_extend( :class, :module ).extend( B )
924
+ cluster( :cluster_name ).after_include_or_extend( :class, :module ).extend( C )
925
+
926
+ end
927
+
928
+ module IncludeModuleMock
929
+ include ClusterModuleMock
930
+ is_a?( A ).should == true
931
+ is_a?( C ).should == true
932
+ eigenclass = class << self ; self ;end
933
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
934
+ end
935
+
936
+ module ExtendModuleMock
937
+ extend ClusterModuleMock
938
+ is_a?( B ).should == true
939
+ is_a?( C ).should == true
940
+ eigenclass = class << self ; self ;end
941
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
942
+ end
943
+
944
+ class IncludeClassMock
945
+ include ClusterModuleMock
946
+ is_a?( A ).should == true
947
+ is_a?( C ).should == true
948
+ eigenclass = class << self ; self ;end
949
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
950
+ end
951
+
952
+ class ExtendClassMock
953
+ extend ClusterModuleMock
954
+ is_a?( B ).should == true
955
+ is_a?( C ).should == true
956
+ eigenclass = class << self ; self ;end
957
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
958
+ end
959
+
960
+ instance = Object.new
961
+ instance.extend( ClusterModuleMock )
962
+ instance.is_a?( A ).should == false
963
+ instance.is_a?( B ).should == false
964
+ instance.is_a?( C ).should == false
965
+
966
+ end
967
+ end
968
+
969
+ # class or instance
970
+
971
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
972
+ module ::Module::Cluster::BeforeClassInstanceConditionalHookMock
973
+
974
+ module A
975
+ end
976
+ module B
977
+ end
978
+ module C
979
+ end
980
+
981
+ module ClusterModuleMock
982
+
983
+ extend ::Module::Cluster
984
+
985
+ cluster( :cluster_name ).before_include( :class, :instance ).extend( A )
986
+ cluster( :cluster_name ).before_extend( :class, :instance ).extend( B )
987
+ cluster( :cluster_name ).before_include_or_extend( :class, :instance ).extend( C )
988
+
989
+ end
990
+
991
+ module IncludeModuleMock
992
+ include ClusterModuleMock
993
+ is_a?( A ).should == false
994
+ is_a?( C ).should == false
995
+ end
996
+
997
+ module ExtendModuleMock
998
+ extend ClusterModuleMock
999
+ is_a?( B ).should == false
1000
+ is_a?( C ).should == false
1001
+ end
1002
+
1003
+ class IncludeClassMock
1004
+ include ClusterModuleMock
1005
+ is_a?( A ).should == true
1006
+ is_a?( C ).should == true
1007
+ eigenclass = class << self ; self ;end
1008
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1009
+ end
1010
+
1011
+ class ExtendClassMock
1012
+ extend ClusterModuleMock
1013
+ is_a?( B ).should == true
1014
+ is_a?( C ).should == true
1015
+ eigenclass = class << self ; self ;end
1016
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1017
+ end
1018
+
1019
+ instance = Object.new
1020
+ instance.extend( ClusterModuleMock )
1021
+ instance.is_a?( B ).should == true
1022
+ instance.is_a?( C ).should == true
1023
+ eigenclass = class << instance ; self ;end
1024
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1025
+
1026
+ end
1027
+ end
1028
+
1029
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
1030
+ module ::Module::Cluster::AfterClassInstanceConditionalHookMock
1031
+
1032
+ module A
1033
+ end
1034
+ module B
1035
+ end
1036
+ module C
1037
+ end
1038
+
1039
+ module ClusterModuleMock
1040
+
1041
+ extend ::Module::Cluster
1042
+
1043
+ cluster( :cluster_name ).after_include( :class, :instance ).extend( A )
1044
+ cluster( :cluster_name ).after_extend( :class, :instance ).extend( B )
1045
+ cluster( :cluster_name ).after_include_or_extend( :class, :instance ).extend( C )
1046
+
1047
+ end
1048
+
1049
+ module IncludeModuleMock
1050
+ include ClusterModuleMock
1051
+ is_a?( A ).should == false
1052
+ is_a?( C ).should == false
1053
+ end
1054
+
1055
+ module ExtendModuleMock
1056
+ extend ClusterModuleMock
1057
+ is_a?( B ).should == false
1058
+ is_a?( C ).should == false
1059
+ end
1060
+
1061
+ class IncludeClassMock
1062
+ include ClusterModuleMock
1063
+ is_a?( A ).should == true
1064
+ is_a?( C ).should == true
1065
+ eigenclass = class << self ; self ;end
1066
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1067
+ end
1068
+
1069
+ class ExtendClassMock
1070
+ extend ClusterModuleMock
1071
+ is_a?( B ).should == true
1072
+ is_a?( C ).should == true
1073
+ eigenclass = class << self ; self ;end
1074
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1075
+ end
1076
+
1077
+ instance = Object.new
1078
+ instance.extend( ClusterModuleMock )
1079
+ instance.is_a?( B ).should == true
1080
+ instance.is_a?( C ).should == true
1081
+ eigenclass = class << instance ; self ;end
1082
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1083
+
1084
+ end
1085
+ end
1086
+
1087
+ # module or instance
1088
+
1089
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
1090
+ module ::Module::Cluster::BeforeModuleInstanceConditionalHookMock
1091
+
1092
+ module A
1093
+ end
1094
+ module B
1095
+ end
1096
+ module C
1097
+ end
1098
+
1099
+ module ClusterModuleMock
1100
+
1101
+ extend ::Module::Cluster
1102
+
1103
+ cluster( :cluster_name ).before_include( :module, :instance ).extend( A )
1104
+ cluster( :cluster_name ).before_extend( :module, :instance ).extend( B )
1105
+ cluster( :cluster_name ).before_include_or_extend( :module, :instance ).extend( C )
1106
+
1107
+ end
1108
+
1109
+ module IncludeModuleMock
1110
+ include ClusterModuleMock
1111
+ is_a?( A ).should == true
1112
+ is_a?( C ).should == true
1113
+ eigenclass = class << self ; self ;end
1114
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1115
+ end
1116
+
1117
+ module ExtendModuleMock
1118
+ extend ClusterModuleMock
1119
+ is_a?( B ).should == true
1120
+ is_a?( C ).should == true
1121
+ eigenclass = class << self ; self ;end
1122
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1123
+ end
1124
+
1125
+ class IncludeClassMock
1126
+ include ClusterModuleMock
1127
+ is_a?( A ).should == false
1128
+ is_a?( C ).should == false
1129
+ end
1130
+
1131
+ class ExtendClassMock
1132
+ extend ClusterModuleMock
1133
+ is_a?( B ).should == false
1134
+ is_a?( C ).should == false
1135
+ end
1136
+
1137
+ instance = Object.new
1138
+ instance.extend( ClusterModuleMock )
1139
+ instance.is_a?( B ).should == true
1140
+ instance.is_a?( C ).should == true
1141
+ eigenclass = class << instance ; self ;end
1142
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1143
+
1144
+ end
1145
+ end
1146
+
1147
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
1148
+ module ::Module::Cluster::AfterModuleInstanceConditionalHookMock
1149
+
1150
+ module A
1151
+ end
1152
+ module B
1153
+ end
1154
+ module C
1155
+ end
1156
+
1157
+ module ClusterModuleMock
1158
+
1159
+ extend ::Module::Cluster
1160
+
1161
+ cluster( :cluster_name ).after_include( :module, :instance ).extend( A )
1162
+ cluster( :cluster_name ).after_extend( :module, :instance ).extend( B )
1163
+ cluster( :cluster_name ).after_include_or_extend( :module, :instance ).extend( C )
1164
+
1165
+ end
1166
+
1167
+ module IncludeModuleMock
1168
+ include ClusterModuleMock
1169
+ is_a?( A ).should == true
1170
+ is_a?( C ).should == true
1171
+ eigenclass = class << self ; self ;end
1172
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1173
+ end
1174
+
1175
+ module ExtendModuleMock
1176
+ extend ClusterModuleMock
1177
+ is_a?( B ).should == true
1178
+ is_a?( C ).should == true
1179
+ eigenclass = class << self ; self ;end
1180
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1181
+ end
1182
+
1183
+ class IncludeClassMock
1184
+ include ClusterModuleMock
1185
+ is_a?( A ).should == false
1186
+ is_a?( C ).should == false
1187
+ end
1188
+
1189
+ class ExtendClassMock
1190
+ extend ClusterModuleMock
1191
+ is_a?( B ).should == false
1192
+ is_a?( C ).should == false
1193
+ end
1194
+
1195
+ instance = Object.new
1196
+ instance.extend( ClusterModuleMock )
1197
+ instance.is_a?( B ).should == true
1198
+ instance.is_a?( C ).should == true
1199
+ eigenclass = class << instance ; self ;end
1200
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1201
+
1202
+ end
1203
+ end
1204
+
1205
+ # class or module or instance (redundant with non-specification)
1206
+
1207
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
1208
+ module ::Module::Cluster::BeforeClassModuleInstanceConditionalHookMock
1209
+
1210
+ module A
1211
+ end
1212
+ module B
1213
+ end
1214
+ module C
1215
+ end
1216
+
1217
+ module ClusterModuleMock
1218
+
1219
+ extend ::Module::Cluster
1220
+
1221
+ cluster( :cluster_name ).after_include( :class, :module, :instance ).extend( A )
1222
+ cluster( :cluster_name ).after_extend( :class, :module, :instance ).extend( B )
1223
+ cluster( :cluster_name ).after_include_or_extend( :class, :module, :instance ).extend( C )
1224
+
1225
+ end
1226
+
1227
+ module IncludeModuleMock
1228
+ include ClusterModuleMock
1229
+ is_a?( A ).should == true
1230
+ is_a?( C ).should == true
1231
+ eigenclass = class << self ; self ;end
1232
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1233
+ end
1234
+
1235
+ module ExtendModuleMock
1236
+ extend ClusterModuleMock
1237
+ is_a?( B ).should == true
1238
+ is_a?( C ).should == true
1239
+ eigenclass = class << self ; self ;end
1240
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1241
+ end
1242
+
1243
+ class IncludeClassMock
1244
+ include ClusterModuleMock
1245
+ is_a?( A ).should == true
1246
+ is_a?( C ).should == true
1247
+ eigenclass = class << self ; self ;end
1248
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1249
+ end
1250
+
1251
+ class ExtendClassMock
1252
+ extend ClusterModuleMock
1253
+ is_a?( B ).should == true
1254
+ is_a?( C ).should == true
1255
+ eigenclass = class << self ; self ;end
1256
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1257
+ end
1258
+
1259
+ instance = Object.new
1260
+ instance.extend( ClusterModuleMock )
1261
+ instance.is_a?( B ).should == true
1262
+ instance.is_a?( C ).should == true
1263
+ eigenclass = class << instance ; self ;end
1264
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1265
+
1266
+ end
1267
+ end
1268
+
1269
+ it 'can qualify conditional include/extend/subclass hooks based on the instance including/extending/subclassing' do
1270
+ module ::Module::Cluster::AfterClassModuleInstanceConditionalHookMock
1271
+
1272
+ module A
1273
+ end
1274
+ module B
1275
+ end
1276
+ module C
1277
+ end
1278
+
1279
+ module ClusterModuleMock
1280
+
1281
+ extend ::Module::Cluster
1282
+
1283
+ cluster( :cluster_name ).after_include( :class, :module, :instance ).extend( A )
1284
+ cluster( :cluster_name ).after_extend( :class, :module, :instance ).extend( B )
1285
+ cluster( :cluster_name ).after_include_or_extend( :class, :module, :instance ).extend( C )
1286
+
1287
+ end
1288
+
1289
+ module IncludeModuleMock
1290
+ include ClusterModuleMock
1291
+ is_a?( A ).should == true
1292
+ is_a?( C ).should == true
1293
+ eigenclass = class << self ; self ;end
1294
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1295
+ end
1296
+
1297
+ module ExtendModuleMock
1298
+ extend ClusterModuleMock
1299
+ is_a?( B ).should == true
1300
+ is_a?( C ).should == true
1301
+ eigenclass = class << self ; self ;end
1302
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1303
+ end
1304
+
1305
+ class IncludeClassMock
1306
+ include ClusterModuleMock
1307
+ is_a?( A ).should == true
1308
+ is_a?( C ).should == true
1309
+ eigenclass = class << self ; self ;end
1310
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( C )
1311
+ end
1312
+
1313
+ class ExtendClassMock
1314
+ extend ClusterModuleMock
1315
+ is_a?( B ).should == true
1316
+ is_a?( C ).should == true
1317
+ eigenclass = class << self ; self ;end
1318
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1319
+ end
1320
+
1321
+ instance = Object.new
1322
+ instance.extend( ClusterModuleMock )
1323
+ instance.is_a?( B ).should == true
1324
+ instance.is_a?( C ).should == true
1325
+ eigenclass = class << instance ; self ;end
1326
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1327
+
1328
+ end
1329
+ end
1330
+
1331
+ #############################
1332
+ # cascading event actions #
1333
+ #############################
1334
+
1335
+ # cascade to any instance (class, subclass, module, instance)
1336
+
1337
+ it 'can create cascade event actions to perform at hook time' do
1338
+ module ::Module::Cluster::CascadeActionMock
1339
+
1340
+ module A
1341
+ end
1342
+ module B
1343
+ end
1344
+ module C
1345
+ end
1346
+ module D
1347
+ end
1348
+ module E
1349
+ end
1350
+ module F
1351
+ end
1352
+
1353
+ block_ran = false
1354
+
1355
+ ClusterModuleMock = ::Module.new
1356
+ ClusterModuleMock.module_eval do
1357
+ extend ::Module::Cluster
1358
+
1359
+ cluster( :before_include_cluster_name ).before_include.cascade.extend( A ) do
1360
+ block_ran = true
1361
+ end
1362
+
1363
+ end
1364
+
1365
+ module IncludingModuleA
1366
+ include ClusterModuleMock
1367
+ is_a?( A ).should == true
1368
+ end
1369
+
1370
+ block_ran.should == true
1371
+
1372
+ block_ran = false
1373
+
1374
+ module IncludingModuleB
1375
+ include IncludingModuleA
1376
+ is_a?( A ).should == true
1377
+ end
1378
+
1379
+ block_ran.should == true
1380
+
1381
+ block_ran = false
1382
+
1383
+ module IncludingModuleC
1384
+ include IncludingModuleB
1385
+ is_a?( A ).should == true
1386
+ end
1387
+
1388
+ block_ran.should == true
1389
+
1390
+ block_ran = false
1391
+
1392
+ module IncludingModuleD
1393
+ include IncludingModuleC
1394
+ is_a?( A ).should == true
1395
+ end
1396
+
1397
+ block_ran.should == true
1398
+
1399
+ block_ran = false
1400
+
1401
+ class IncludingClassA
1402
+ include IncludingModuleC
1403
+ is_a?( A ).should == true
1404
+ end
1405
+
1406
+ block_ran.should == true
1407
+
1408
+ block_ran = false
1409
+
1410
+ class IncludingClassB < IncludingClassA
1411
+ is_a?( A ).should == true
1412
+ end
1413
+
1414
+ block_ran.should == true
1415
+
1416
+ block_ran = false
1417
+
1418
+ class IncludingClassC < IncludingClassB
1419
+ is_a?( A ).should == true
1420
+ end
1421
+
1422
+ end
1423
+ end
1424
+
1425
+ # cascade to class
1426
+ # this means to the first class, not subclasses
1427
+
1428
+ it 'can create cascade event actions to perform at hook time' do
1429
+ module ::Module::Cluster::CascadeToClassActionMock
1430
+
1431
+ module A
1432
+ end
1433
+
1434
+ block_ran = false
1435
+
1436
+ ClusterModuleMock = ::Module.new
1437
+ ClusterModuleMock.module_eval do
1438
+ extend ::Module::Cluster
1439
+
1440
+ cluster( :before_include_cluster_name ).before_include.cascade( :class ).extend( A ) do
1441
+ block_ran = true
1442
+ end
1443
+
1444
+ end
1445
+
1446
+ module IncludingModuleA
1447
+ include ClusterModuleMock
1448
+ is_a?( A ).should == false
1449
+ end
1450
+
1451
+ block_ran.should == false
1452
+
1453
+ module IncludingModuleB
1454
+ include IncludingModuleA
1455
+ is_a?( A ).should == false
1456
+ end
1457
+
1458
+ block_ran.should == false
1459
+
1460
+ module IncludingModuleC
1461
+ include IncludingModuleB
1462
+ is_a?( A ).should == false
1463
+ end
1464
+
1465
+ block_ran.should == false
1466
+
1467
+ module IncludingModuleD
1468
+ include IncludingModuleC
1469
+ is_a?( A ).should == false
1470
+ end
1471
+
1472
+ block_ran.should == false
1473
+
1474
+ class IncludingClassA
1475
+ include IncludingModuleD
1476
+ is_a?( A ).should == true
1477
+ end
1478
+
1479
+ block_ran.should == true
1480
+
1481
+ block_ran = false
1482
+
1483
+ class IncludingClassB < IncludingClassA
1484
+ is_a?( A ).should == true
1485
+ end
1486
+
1487
+ block_ran.should == false
1488
+
1489
+ block_ran = false
1490
+
1491
+ class IncludingClassC < IncludingClassB
1492
+ is_a?( A ).should == true
1493
+ end
1494
+
1495
+ end
1496
+ end
1497
+
1498
+ # cascade to subclass
1499
+
1500
+ it 'can create cascade event actions to perform at hook time' do
1501
+ module ::Module::Cluster::CascadeToSubclassActionMock
1502
+
1503
+ module A
1504
+ end
1505
+
1506
+ block_ran = false
1507
+
1508
+ ClusterModuleMock = ::Module.new
1509
+ ClusterModuleMock.module_eval do
1510
+ extend ::Module::Cluster
1511
+
1512
+ cluster( :before_include_cluster_name ).before_include.cascade( :subclass ).extend( A ) do
1513
+ block_ran = true
1514
+ end
1515
+
1516
+ end
1517
+
1518
+ module IncludingModuleA
1519
+ include ClusterModuleMock
1520
+ is_a?( A ).should == false
1521
+ end
1522
+
1523
+ block_ran.should == false
1524
+
1525
+ module IncludingModuleB
1526
+ include IncludingModuleA
1527
+ is_a?( A ).should == false
1528
+ end
1529
+
1530
+ block_ran.should == false
1531
+
1532
+ module IncludingModuleC
1533
+ include IncludingModuleB
1534
+ is_a?( A ).should == false
1535
+ end
1536
+
1537
+ block_ran.should == false
1538
+
1539
+ module IncludingModuleD
1540
+ include IncludingModuleC
1541
+ is_a?( A ).should == false
1542
+ end
1543
+
1544
+ block_ran.should == false
1545
+
1546
+ class IncludingClassA
1547
+ include IncludingModuleD
1548
+ is_a?( A ).should == false
1549
+ end
1550
+
1551
+ block_ran.should == false
1552
+
1553
+ block_ran = false
1554
+
1555
+ class IncludingClassB < IncludingClassA
1556
+ is_a?( A ).should == true
1557
+ end
1558
+
1559
+ block_ran.should == true
1560
+
1561
+ block_ran = false
1562
+
1563
+ class IncludingClassC < IncludingClassB
1564
+ is_a?( A ).should == true
1565
+ end
1566
+
1567
+ end
1568
+ end
1569
+
1570
+ # cascade to module
1571
+
1572
+ it 'can create cascade event actions to perform at hook time' do
1573
+ module ::Module::Cluster::CascadeToModuleActionMock
1574
+
1575
+ module A
1576
+ end
1577
+
1578
+ block_ran = false
1579
+
1580
+ ClusterModuleMock = ::Module.new
1581
+ ClusterModuleMock.module_eval do
1582
+ extend ::Module::Cluster
1583
+
1584
+ cluster( :before_include_cluster_name ).before_include.cascade( :module ).extend( A ) do
1585
+ block_ran = true
1586
+ end
1587
+
1588
+ end
1589
+
1590
+ module IncludingModuleA
1591
+ include ClusterModuleMock
1592
+ is_a?( A ).should == true
1593
+ end
1594
+
1595
+ block_ran.should == true
1596
+
1597
+ block_ran = false
1598
+
1599
+ module IncludingModuleB
1600
+ include IncludingModuleA
1601
+ is_a?( A ).should == true
1602
+ end
1603
+
1604
+ block_ran.should == true
1605
+
1606
+ block_ran = false
1607
+
1608
+ module IncludingModuleC
1609
+ include IncludingModuleB
1610
+ is_a?( A ).should == true
1611
+ end
1612
+
1613
+ block_ran.should == true
1614
+
1615
+ block_ran = false
1616
+
1617
+ module IncludingModuleD
1618
+ include IncludingModuleC
1619
+ is_a?( A ).should == true
1620
+ end
1621
+
1622
+ block_ran.should == true
1623
+
1624
+ block_ran = false
1625
+
1626
+ class IncludingClassA
1627
+ include IncludingModuleD
1628
+ is_a?( A ).should == false
1629
+ end
1630
+
1631
+ block_ran.should == false
1632
+
1633
+ class IncludingClassB < IncludingClassA
1634
+ is_a?( A ).should == false
1635
+ end
1636
+
1637
+ block_ran.should == false
1638
+
1639
+ class IncludingClassC < IncludingClassB
1640
+ is_a?( A ).should == false
1641
+ end
1642
+
1643
+ end
1644
+ end
1645
+
1646
+ # cascade to class or subclass
1647
+
1648
+ it 'can create cascade event actions to perform at hook time' do
1649
+ module ::Module::Cluster::CascadeToClassOrSubclassActionMock
1650
+
1651
+ module A
1652
+ end
1653
+
1654
+ block_ran = false
1655
+
1656
+ ClusterModuleMock = ::Module.new
1657
+ ClusterModuleMock.module_eval do
1658
+ extend ::Module::Cluster
1659
+
1660
+ cluster( :before_include_cluster_name ).before_include.cascade( :class, :subclass ).extend( A ) do
1661
+ block_ran = true
1662
+ end
1663
+
1664
+ end
1665
+
1666
+ module IncludingModuleA
1667
+ include ClusterModuleMock
1668
+ is_a?( A ).should == false
1669
+ end
1670
+
1671
+ block_ran.should == false
1672
+
1673
+ module IncludingModuleB
1674
+ include IncludingModuleA
1675
+ is_a?( A ).should == false
1676
+ end
1677
+
1678
+ block_ran.should == false
1679
+
1680
+ module IncludingModuleC
1681
+ include IncludingModuleB
1682
+ is_a?( A ).should == false
1683
+ end
1684
+
1685
+ block_ran.should == false
1686
+
1687
+ module IncludingModuleD
1688
+ include IncludingModuleC
1689
+ is_a?( A ).should == false
1690
+ end
1691
+
1692
+ block_ran.should == false
1693
+
1694
+ class IncludingClassA
1695
+ include IncludingModuleD
1696
+ is_a?( A ).should == true
1697
+ end
1698
+
1699
+ block_ran.should == true
1700
+
1701
+ block_ran = false
1702
+
1703
+ class IncludingClassB < IncludingClassA
1704
+ is_a?( A ).should == true
1705
+ end
1706
+
1707
+ block_ran.should == true
1708
+
1709
+ block_ran = false
1710
+
1711
+ class IncludingClassC < IncludingClassB
1712
+ is_a?( A ).should == true
1713
+ end
1714
+
1715
+ end
1716
+ end
1717
+
1718
+ #######################################
1719
+ # suspend and resume named clusters #
1720
+ #######################################
1721
+
1722
+ it 'can suspend and resume named clusters' do
1723
+ module ::Module::Cluster::SuspendResumeMock
1724
+
1725
+ module ClusterModuleMock
1726
+
1727
+ extend ::Module::Cluster
1728
+
1729
+ module A
1730
+ end
1731
+ module B
1732
+ end
1733
+ module C
1734
+ end
1735
+
1736
+ cluster( :cluster_name ).before_include.extend( A, B, C )
1737
+
1738
+ module D
1739
+ end
1740
+ module E
1741
+ end
1742
+ module F
1743
+ end
1744
+
1745
+ cluster( :other_cluster_name ).before_include.extend( D, E, F )
1746
+
1747
+ end
1748
+
1749
+ module IncludingModule
1750
+
1751
+ include ClusterModuleMock
1752
+
1753
+ is_a?( A ).should == true
1754
+ is_a?( B ).should == true
1755
+ is_a?( C ).should == true
1756
+ is_a?( D ).should == true
1757
+ is_a?( E ).should == true
1758
+ is_a?( F ).should == true
1759
+
1760
+ eigenclass = class << self ; self ;end
1761
+
1762
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( B )
1763
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1764
+ eigenclass.ancestors.index( C ).should > eigenclass.ancestors.index( D )
1765
+ eigenclass.ancestors.index( D ).should > eigenclass.ancestors.index( E )
1766
+ eigenclass.ancestors.index( E ).should > eigenclass.ancestors.index( F )
1767
+
1768
+ end
1769
+
1770
+ module OtherIncludingModule
1771
+
1772
+ ClusterModuleMock.cluster( :other_cluster_name ).disable
1773
+
1774
+ include ClusterModuleMock
1775
+
1776
+ is_a?( A ).should == true
1777
+ is_a?( B ).should == true
1778
+ is_a?( C ).should == true
1779
+ is_a?( D ).should == false
1780
+ is_a?( E ).should == false
1781
+ is_a?( F ).should == false
1782
+
1783
+ eigenclass = class << self ; self ;end
1784
+
1785
+ eigenclass.ancestors.index( A ).should > eigenclass.ancestors.index( B )
1786
+ eigenclass.ancestors.index( B ).should > eigenclass.ancestors.index( C )
1787
+
1788
+ end
1789
+
1790
+ end
1791
+
1792
+ end
1793
+
1794
+ end