module-cluster 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/module/cluster/instance_controller/instance_controller_interface.rb +1 -1
- data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy.rb +20 -20
- data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy/chain_proxy.rb +18 -18
- data/spec/module/cluster_spec.rb +1195 -0
- metadata +2 -2
@@ -115,7 +115,7 @@ module ::Module::Cluster::InstanceController::InstanceControllerInterface
|
|
115
115
|
def before_extend_subclass_proxy
|
116
116
|
|
117
117
|
return @before_extend_subclass_proxy ||= self.class::MultipleHookControllerProxy.new( :before_extend_subclass,
|
118
|
-
|
118
|
+
before_extend_controller,
|
119
119
|
subclass_controller )
|
120
120
|
|
121
121
|
end
|
@@ -40,10 +40,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
40
40
|
#
|
41
41
|
# @return [Module::Cluster::InstanceController::HookController] self
|
42
42
|
#
|
43
|
-
def include( *modules )
|
43
|
+
def include( *modules, & block )
|
44
44
|
|
45
45
|
@hook_controllers.each do |this_hook_controller|
|
46
|
-
this_hook_controller.include( *modules )
|
46
|
+
this_hook_controller.include( *modules, & block )
|
47
47
|
end
|
48
48
|
|
49
49
|
return self
|
@@ -67,10 +67,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
67
67
|
#
|
68
68
|
# @return [Module::Cluster::InstanceController::HookController] self
|
69
69
|
#
|
70
|
-
def extend( *modules )
|
70
|
+
def extend( *modules, & block )
|
71
71
|
|
72
72
|
@hook_controllers.each do |this_hook_controller|
|
73
|
-
this_hook_controller.extend( *modules )
|
73
|
+
this_hook_controller.extend( *modules, & block )
|
74
74
|
end
|
75
75
|
|
76
76
|
return self
|
@@ -94,10 +94,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
94
94
|
#
|
95
95
|
# @return [Module::Cluster::InstanceController::HookController] self
|
96
96
|
#
|
97
|
-
def include_and_extend( *modules )
|
97
|
+
def include_and_extend( *modules, & block )
|
98
98
|
|
99
99
|
@hook_controllers.each do |this_hook_controller|
|
100
|
-
this_hook_controller.include_and_extend( *modules )
|
100
|
+
this_hook_controller.include_and_extend( *modules, & block )
|
101
101
|
end
|
102
102
|
|
103
103
|
return self
|
@@ -121,10 +121,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
121
121
|
#
|
122
122
|
# @return [Module::Cluster::InstanceController::HookController] self
|
123
123
|
#
|
124
|
-
def extend_and_include( *modules )
|
124
|
+
def extend_and_include( *modules, & block )
|
125
125
|
|
126
126
|
@hook_controllers.each do |this_hook_controller|
|
127
|
-
this_hook_controller.extend_and_include( *modules )
|
127
|
+
this_hook_controller.extend_and_include( *modules, & block )
|
128
128
|
end
|
129
129
|
|
130
130
|
return self
|
@@ -172,9 +172,9 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
172
172
|
#
|
173
173
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Chain Proxy for chained declarations.
|
174
174
|
#
|
175
|
-
def before_extend( *modules )
|
175
|
+
def before_extend( *modules, & block )
|
176
176
|
|
177
|
-
return chain_proxy.before_extend( *modules )
|
177
|
+
return chain_proxy.before_extend( *modules, & block )
|
178
178
|
|
179
179
|
end
|
180
180
|
|
@@ -196,9 +196,9 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
196
196
|
#
|
197
197
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Chain Proxy for chained declarations.
|
198
198
|
#
|
199
|
-
def before_include( *modules )
|
199
|
+
def before_include( *modules, & block )
|
200
200
|
|
201
|
-
return chain_proxy.before_include( *modules )
|
201
|
+
return chain_proxy.before_include( *modules, & block )
|
202
202
|
|
203
203
|
end
|
204
204
|
|
@@ -221,9 +221,9 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
221
221
|
#
|
222
222
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Chain Proxy for chained declarations.
|
223
223
|
#
|
224
|
-
def before_include_or_extend( *modules )
|
224
|
+
def before_include_or_extend( *modules, & block )
|
225
225
|
|
226
|
-
return chain_proxy.before_include_or_extend( *modules )
|
226
|
+
return chain_proxy.before_include_or_extend( *modules, & block )
|
227
227
|
|
228
228
|
end
|
229
229
|
|
@@ -247,9 +247,9 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
247
247
|
#
|
248
248
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Chain Proxy for chained declarations.
|
249
249
|
#
|
250
|
-
def after_include( *modules )
|
250
|
+
def after_include( *modules, & block )
|
251
251
|
|
252
|
-
return chain_proxy.after_include( *modules )
|
252
|
+
return chain_proxy.after_include( *modules, & block )
|
253
253
|
|
254
254
|
end
|
255
255
|
|
@@ -271,9 +271,9 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
271
271
|
#
|
272
272
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Chain Proxy for chained declarations.
|
273
273
|
#
|
274
|
-
def after_extend( *modules )
|
274
|
+
def after_extend( *modules, & block )
|
275
275
|
|
276
|
-
return chain_proxy.after_extend( *modules )
|
276
|
+
return chain_proxy.after_extend( *modules, & block )
|
277
277
|
|
278
278
|
end
|
279
279
|
|
@@ -296,9 +296,9 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy
|
|
296
296
|
#
|
297
297
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Chain Proxy for chained declarations.
|
298
298
|
#
|
299
|
-
def after_include_or_extend( *modules )
|
299
|
+
def after_include_or_extend( *modules, & block )
|
300
300
|
|
301
|
-
return chain_proxy.after_include_or_extend( *modules )
|
301
|
+
return chain_proxy.after_include_or_extend( *modules, & block )
|
302
302
|
|
303
303
|
end
|
304
304
|
|
@@ -66,10 +66,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
66
66
|
#
|
67
67
|
# @return [Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainProxy] self
|
68
68
|
#
|
69
|
-
def extend( *modules )
|
69
|
+
def extend( *modules, & block )
|
70
70
|
|
71
71
|
@proxies.each do |this_hook_controller_chain_proxy|
|
72
|
-
this_hook_controller_chain_proxy.extend( *modules )
|
72
|
+
this_hook_controller_chain_proxy.extend( *modules, & block )
|
73
73
|
end
|
74
74
|
|
75
75
|
return self
|
@@ -94,10 +94,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
94
94
|
#
|
95
95
|
# @return [Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainProxy] self
|
96
96
|
#
|
97
|
-
def include_and_extend( *modules )
|
97
|
+
def include_and_extend( *modules, & block )
|
98
98
|
|
99
99
|
@proxies.each do |this_hook_controller_chain_proxy|
|
100
|
-
this_hook_controller_chain_proxy.include_and_extend( *modules )
|
100
|
+
this_hook_controller_chain_proxy.include_and_extend( *modules, & block )
|
101
101
|
end
|
102
102
|
|
103
103
|
return self
|
@@ -122,10 +122,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
122
122
|
#
|
123
123
|
# @return [Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainProxy] self
|
124
124
|
#
|
125
|
-
def extend_and_include( *modules )
|
125
|
+
def extend_and_include( *modules, & block )
|
126
126
|
|
127
127
|
@proxies.each do |this_hook_controller_chain_proxy|
|
128
|
-
this_hook_controller_chain_proxy.extend_and_include( *modules )
|
128
|
+
this_hook_controller_chain_proxy.extend_and_include( *modules, & block )
|
129
129
|
end
|
130
130
|
|
131
131
|
return self
|
@@ -204,10 +204,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
204
204
|
#
|
205
205
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Self.
|
206
206
|
#
|
207
|
-
def before_extend( *modules )
|
207
|
+
def before_extend( *modules, & block )
|
208
208
|
|
209
209
|
@proxies.each do |this_hook_controller_chain_proxy|
|
210
|
-
this_hook_controller_chain_proxy.before_extend( *modules )
|
210
|
+
this_hook_controller_chain_proxy.before_extend( *modules, & block )
|
211
211
|
end
|
212
212
|
|
213
213
|
return self
|
@@ -232,10 +232,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
232
232
|
#
|
233
233
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Self.
|
234
234
|
#
|
235
|
-
def before_include( *modules )
|
235
|
+
def before_include( *modules, & block )
|
236
236
|
|
237
237
|
@proxies.each do |this_hook_controller_chain_proxy|
|
238
|
-
this_hook_controller_chain_proxy.before_include( *modules )
|
238
|
+
this_hook_controller_chain_proxy.before_include( *modules, & block )
|
239
239
|
end
|
240
240
|
|
241
241
|
return self
|
@@ -261,10 +261,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
261
261
|
#
|
262
262
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Self.
|
263
263
|
#
|
264
|
-
def before_include_or_extend( *modules )
|
264
|
+
def before_include_or_extend( *modules, & block )
|
265
265
|
|
266
266
|
@proxies.each do |this_hook_controller_chain_proxy|
|
267
|
-
this_hook_controller_chain_proxy.before_include_or_extend( *modules )
|
267
|
+
this_hook_controller_chain_proxy.before_include_or_extend( *modules, & block )
|
268
268
|
end
|
269
269
|
|
270
270
|
return self
|
@@ -291,10 +291,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
291
291
|
#
|
292
292
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Self.
|
293
293
|
#
|
294
|
-
def after_include( *modules )
|
294
|
+
def after_include( *modules, & block )
|
295
295
|
|
296
296
|
@proxies.each do |this_hook_controller_chain_proxy|
|
297
|
-
this_hook_controller_chain_proxy.after_include( *modules )
|
297
|
+
this_hook_controller_chain_proxy.after_include( *modules, & block )
|
298
298
|
end
|
299
299
|
|
300
300
|
return self
|
@@ -319,10 +319,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
319
319
|
#
|
320
320
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Self.
|
321
321
|
#
|
322
|
-
def after_extend( *modules )
|
322
|
+
def after_extend( *modules, & block )
|
323
323
|
|
324
324
|
@proxies.each do |this_hook_controller_chain_proxy|
|
325
|
-
this_hook_controller_chain_proxy.after_extend( *modules )
|
325
|
+
this_hook_controller_chain_proxy.after_extend( *modules, & block )
|
326
326
|
end
|
327
327
|
|
328
328
|
return self
|
@@ -348,10 +348,10 @@ class ::Module::Cluster::InstanceController::MultipleHookControllerProxy::ChainP
|
|
348
348
|
#
|
349
349
|
# @return [Module::Cluster::InstanceController::HookController::ChainProxy] Self.
|
350
350
|
#
|
351
|
-
def after_include_or_extend( *modules )
|
351
|
+
def after_include_or_extend( *modules, & block )
|
352
352
|
|
353
353
|
@proxies.each do |this_hook_controller_chain_proxy|
|
354
|
-
this_hook_controller_chain_proxy.after_include_or_extend( *modules )
|
354
|
+
this_hook_controller_chain_proxy.after_include_or_extend( *modules, & block )
|
355
355
|
end
|
356
356
|
|
357
357
|
return self
|
data/spec/module/cluster_spec.rb
CHANGED
@@ -524,6 +524,8 @@ describe ::Module::Cluster do
|
|
524
524
|
end
|
525
525
|
|
526
526
|
block_ran.should == true
|
527
|
+
|
528
|
+
block_ran = false
|
527
529
|
|
528
530
|
class AnotherClassC < AnotherClassB
|
529
531
|
is_a?( A ).should == true
|
@@ -633,6 +635,1199 @@ describe ::Module::Cluster do
|
|
633
635
|
end
|
634
636
|
end
|
635
637
|
|
638
|
+
##############################
|
639
|
+
# before_include_or_extend #
|
640
|
+
##############################
|
641
|
+
|
642
|
+
it 'can simultaneously create hooks for both before-include and before-extend - with block only' do
|
643
|
+
module ::Module::Cluster::BeforeIncludeExtendHookBlockOnlyMock
|
644
|
+
|
645
|
+
block_ran = false
|
646
|
+
|
647
|
+
ClusterModuleMock = ::Module.new
|
648
|
+
ClusterModuleMock.module_eval do
|
649
|
+
extend ::Module::Cluster
|
650
|
+
block = ::Proc.new do |instance|
|
651
|
+
block_ran = true
|
652
|
+
end
|
653
|
+
cluster( :cluster_name ).before_include_or_extend( & block )
|
654
|
+
end
|
655
|
+
|
656
|
+
class BaseClassInclude
|
657
|
+
include ClusterModuleMock
|
658
|
+
end
|
659
|
+
|
660
|
+
block_ran.should == true
|
661
|
+
|
662
|
+
block_ran = false
|
663
|
+
|
664
|
+
class BaseClassExtend
|
665
|
+
extend ClusterModuleMock
|
666
|
+
end
|
667
|
+
|
668
|
+
block_ran.should == true
|
669
|
+
|
670
|
+
end
|
671
|
+
end
|
672
|
+
|
673
|
+
it 'can simultaneously create hooks for both before-include and before-extend - without block' do
|
674
|
+
module ::Module::Cluster::BeforeIncludeExtendHookMock
|
675
|
+
|
676
|
+
module A
|
677
|
+
end
|
678
|
+
|
679
|
+
module ClusterModuleMock
|
680
|
+
extend ::Module::Cluster
|
681
|
+
cluster( :cluster_name ).before_include_or_extend.extend( A )
|
682
|
+
def self.included( instance )
|
683
|
+
instance.is_a?( A ).should == true
|
684
|
+
super if defined?( super )
|
685
|
+
end
|
686
|
+
def self.extended( instance )
|
687
|
+
instance.is_a?( A ).should == true
|
688
|
+
super if defined?( super )
|
689
|
+
end
|
690
|
+
end
|
691
|
+
|
692
|
+
class BaseClassInclude
|
693
|
+
include ClusterModuleMock
|
694
|
+
is_a?( A ).should == true
|
695
|
+
end
|
696
|
+
|
697
|
+
class BaseClassExtend
|
698
|
+
extend ClusterModuleMock
|
699
|
+
is_a?( A ).should == true
|
700
|
+
end
|
701
|
+
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
it 'can simultaneously create hooks for both before-include and before-extend - with block' do
|
706
|
+
module ::Module::Cluster::BeforeIncludeExtendHookBlockMock
|
707
|
+
|
708
|
+
module A
|
709
|
+
end
|
710
|
+
|
711
|
+
block_ran = false
|
712
|
+
|
713
|
+
ClusterModuleMock = ::Module.new
|
714
|
+
ClusterModuleMock.module_eval do
|
715
|
+
extend ::Module::Cluster
|
716
|
+
block = ::Proc.new do |instance|
|
717
|
+
instance.is_a?( A ).should == true
|
718
|
+
block_ran = true
|
719
|
+
end
|
720
|
+
cluster( :cluster_name ).before_include_or_extend.extend( A, & block )
|
721
|
+
def self.included( instance )
|
722
|
+
instance.is_a?( A ).should == true
|
723
|
+
super if defined?( super )
|
724
|
+
end
|
725
|
+
def self.extended( instance )
|
726
|
+
instance.is_a?( A ).should == true
|
727
|
+
super if defined?( super )
|
728
|
+
end
|
729
|
+
end
|
730
|
+
|
731
|
+
class BaseClassInclude
|
732
|
+
include ClusterModuleMock
|
733
|
+
is_a?( A ).should == true
|
734
|
+
end
|
735
|
+
|
736
|
+
block_ran.should == true
|
737
|
+
|
738
|
+
block_ran = false
|
739
|
+
|
740
|
+
class BaseClassExtend
|
741
|
+
extend ClusterModuleMock
|
742
|
+
is_a?( A ).should == true
|
743
|
+
end
|
744
|
+
|
745
|
+
block_ran.should == true
|
746
|
+
|
747
|
+
end
|
748
|
+
end
|
749
|
+
|
750
|
+
#############################
|
751
|
+
# after_include_or_extend #
|
752
|
+
#############################
|
753
|
+
|
754
|
+
it 'can simultaneously create hooks for both after-include and after-extend - with block only' do
|
755
|
+
module ::Module::Cluster::AfterIncludeExtendHookBlockOnlyMock
|
756
|
+
|
757
|
+
block_ran = false
|
758
|
+
|
759
|
+
ClusterModuleMock = ::Module.new
|
760
|
+
ClusterModuleMock.module_eval do
|
761
|
+
extend ::Module::Cluster
|
762
|
+
block = ::Proc.new do |instance|
|
763
|
+
block_ran = true
|
764
|
+
end
|
765
|
+
cluster( :cluster_name ).after_include_or_extend( & block )
|
766
|
+
end
|
767
|
+
|
768
|
+
class BaseClassInclude
|
769
|
+
include ClusterModuleMock
|
770
|
+
end
|
771
|
+
|
772
|
+
block_ran.should == true
|
773
|
+
|
774
|
+
block_ran = false
|
775
|
+
|
776
|
+
class BaseClassExtend
|
777
|
+
extend ClusterModuleMock
|
778
|
+
end
|
779
|
+
|
780
|
+
block_ran.should == true
|
781
|
+
|
782
|
+
end
|
783
|
+
end
|
784
|
+
|
785
|
+
it 'can simultaneously create hooks for both after-include and after-extend - without block' do
|
786
|
+
module ::Module::Cluster::AfterIncludeExtendHookMock
|
787
|
+
|
788
|
+
module A
|
789
|
+
end
|
790
|
+
|
791
|
+
module ClusterModuleMock
|
792
|
+
extend ::Module::Cluster
|
793
|
+
cluster( :cluster_name ).after_include_or_extend.extend( A )
|
794
|
+
def self.included( instance )
|
795
|
+
instance.is_a?( A ).should == false
|
796
|
+
super if defined?( super )
|
797
|
+
instance.is_a?( A ).should == true
|
798
|
+
end
|
799
|
+
def self.extended( instance )
|
800
|
+
instance.is_a?( A ).should == false
|
801
|
+
super if defined?( super )
|
802
|
+
instance.is_a?( A ).should == true
|
803
|
+
end
|
804
|
+
end
|
805
|
+
|
806
|
+
class BaseClassInclude
|
807
|
+
include ClusterModuleMock
|
808
|
+
is_a?( A ).should == true
|
809
|
+
end
|
810
|
+
|
811
|
+
class BaseClassExtend
|
812
|
+
extend ClusterModuleMock
|
813
|
+
is_a?( A ).should == true
|
814
|
+
end
|
815
|
+
|
816
|
+
end
|
817
|
+
end
|
818
|
+
|
819
|
+
it 'can simultaneously create hooks for both after-include and after-extend - with block' do
|
820
|
+
module ::Module::Cluster::AfterIncludeExtendHookBlockMock
|
821
|
+
|
822
|
+
module A
|
823
|
+
end
|
824
|
+
|
825
|
+
block_ran = false
|
826
|
+
|
827
|
+
ClusterModuleMock = ::Module.new
|
828
|
+
ClusterModuleMock.module_eval do
|
829
|
+
extend ::Module::Cluster
|
830
|
+
block = ::Proc.new do |instance|
|
831
|
+
instance.is_a?( A ).should == true
|
832
|
+
block_ran = true
|
833
|
+
end
|
834
|
+
cluster( :cluster_name ).after_include_or_extend.extend( A, & block )
|
835
|
+
def self.included( instance )
|
836
|
+
instance.is_a?( A ).should == false
|
837
|
+
super if defined?( super )
|
838
|
+
instance.is_a?( A ).should == true
|
839
|
+
end
|
840
|
+
def self.extended( instance )
|
841
|
+
instance.is_a?( A ).should == false
|
842
|
+
super if defined?( super )
|
843
|
+
instance.is_a?( A ).should == true
|
844
|
+
end
|
845
|
+
end
|
846
|
+
|
847
|
+
class BaseClassInclude
|
848
|
+
include ClusterModuleMock
|
849
|
+
is_a?( A ).should == true
|
850
|
+
end
|
851
|
+
|
852
|
+
block_ran.should == true
|
853
|
+
|
854
|
+
block_ran = false
|
855
|
+
|
856
|
+
class BaseClassExtend
|
857
|
+
extend ClusterModuleMock
|
858
|
+
is_a?( A ).should == true
|
859
|
+
end
|
860
|
+
|
861
|
+
block_ran.should == true
|
862
|
+
|
863
|
+
end
|
864
|
+
end
|
865
|
+
|
866
|
+
################################
|
867
|
+
# before_include_or_subclass #
|
868
|
+
################################
|
869
|
+
|
870
|
+
it 'can simultaneously create hooks for both before-include and subclass - with block only' do
|
871
|
+
module ::Module::Cluster::BeforeIncludeSubclassHookBlockOnlyMock
|
872
|
+
|
873
|
+
block_ran = false
|
874
|
+
|
875
|
+
ClusterModuleMock = ::Module.new
|
876
|
+
ClusterModuleMock.module_eval do
|
877
|
+
extend ::Module::Cluster
|
878
|
+
block = ::Proc.new do |instance|
|
879
|
+
block_ran = true
|
880
|
+
end
|
881
|
+
cluster( :cluster_name ).before_include_or_subclass( & block )
|
882
|
+
end
|
883
|
+
|
884
|
+
class BaseClassInclude
|
885
|
+
include ClusterModuleMock
|
886
|
+
end
|
887
|
+
|
888
|
+
block_ran.should == true
|
889
|
+
|
890
|
+
block_ran = false
|
891
|
+
|
892
|
+
class BaseClassIncludeSub < BaseClassInclude
|
893
|
+
end
|
894
|
+
|
895
|
+
block_ran.should == true
|
896
|
+
|
897
|
+
block_ran = false
|
898
|
+
|
899
|
+
class BaseClassExtend
|
900
|
+
extend ClusterModuleMock
|
901
|
+
end
|
902
|
+
|
903
|
+
block_ran.should == false
|
904
|
+
|
905
|
+
block_ran = false
|
906
|
+
|
907
|
+
class BaseClassExtendSub < BaseClassExtend
|
908
|
+
end
|
909
|
+
|
910
|
+
block_ran.should == true
|
911
|
+
|
912
|
+
end
|
913
|
+
end
|
914
|
+
|
915
|
+
it 'can simultaneously create hooks for both before-include and subclass - without block' do
|
916
|
+
module ::Module::Cluster::BeforeIncludeSubclassHookMock
|
917
|
+
|
918
|
+
module A
|
919
|
+
end
|
920
|
+
|
921
|
+
module ClusterModuleMock
|
922
|
+
extend ::Module::Cluster
|
923
|
+
cluster( :cluster_name ).before_include_or_subclass.extend( A )
|
924
|
+
def self.included( instance )
|
925
|
+
instance.is_a?( A ).should == true
|
926
|
+
super if defined?( super )
|
927
|
+
end
|
928
|
+
def self.extended( instance )
|
929
|
+
instance.is_a?( A ).should == false
|
930
|
+
super if defined?( super )
|
931
|
+
instance.is_a?( A ).should == false
|
932
|
+
end
|
933
|
+
end
|
934
|
+
|
935
|
+
class BaseClassInclude
|
936
|
+
include ClusterModuleMock
|
937
|
+
is_a?( A ).should == true
|
938
|
+
def self.inherited( instance )
|
939
|
+
instance.is_a?( A ).should == true
|
940
|
+
super if defined?( super )
|
941
|
+
end
|
942
|
+
end
|
943
|
+
|
944
|
+
class BaseClassIncludeSub < BaseClassInclude
|
945
|
+
is_a?( A ).should == true
|
946
|
+
end
|
947
|
+
|
948
|
+
class BaseClassExtend
|
949
|
+
extend ClusterModuleMock
|
950
|
+
is_a?( A ).should == false
|
951
|
+
def self.inherited( instance )
|
952
|
+
instance.is_a?( A ).should == false
|
953
|
+
super if defined?( super )
|
954
|
+
instance.is_a?( A ).should == true
|
955
|
+
end
|
956
|
+
end
|
957
|
+
|
958
|
+
class BaseClassExtendSub < BaseClassExtend
|
959
|
+
is_a?( A ).should == true
|
960
|
+
end
|
961
|
+
|
962
|
+
end
|
963
|
+
end
|
964
|
+
|
965
|
+
it 'can simultaneously create hooks for both before-include and subclass - with block' do
|
966
|
+
module ::Module::Cluster::BeforeIncludeSubclassHookBlockMock
|
967
|
+
|
968
|
+
module A
|
969
|
+
end
|
970
|
+
|
971
|
+
block_ran = false
|
972
|
+
|
973
|
+
ClusterModuleMock = ::Module.new
|
974
|
+
ClusterModuleMock.module_eval do
|
975
|
+
extend ::Module::Cluster
|
976
|
+
block = ::Proc.new do |instance|
|
977
|
+
instance.is_a?( A ).should == true
|
978
|
+
block_ran = true
|
979
|
+
end
|
980
|
+
cluster( :cluster_name ).before_include_or_subclass.extend( A, & block )
|
981
|
+
def self.included( instance )
|
982
|
+
instance.is_a?( A ).should == true
|
983
|
+
super if defined?( super )
|
984
|
+
end
|
985
|
+
def self.extended( instance )
|
986
|
+
instance.is_a?( A ).should == false
|
987
|
+
super if defined?( super )
|
988
|
+
end
|
989
|
+
end
|
990
|
+
|
991
|
+
class BaseClassInclude
|
992
|
+
include ClusterModuleMock
|
993
|
+
is_a?( A ).should == true
|
994
|
+
end
|
995
|
+
|
996
|
+
block_ran.should == true
|
997
|
+
|
998
|
+
block_ran = false
|
999
|
+
|
1000
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1001
|
+
is_a?( A ).should == true
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
class BaseClassExtend
|
1005
|
+
extend ClusterModuleMock
|
1006
|
+
is_a?( A ).should == false
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
block_ran.should == true
|
1010
|
+
|
1011
|
+
block_ran = false
|
1012
|
+
|
1013
|
+
class BaseClassExtendSub < BaseClassExtend
|
1014
|
+
is_a?( A ).should == true
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
block_ran.should == true
|
1018
|
+
|
1019
|
+
end
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
###############################
|
1023
|
+
# after_include_or_subclass #
|
1024
|
+
###############################
|
1025
|
+
|
1026
|
+
it 'can simultaneously create hooks for both after-include and subclass - with block' do
|
1027
|
+
module ::Module::Cluster::AfterIncludeSubclassHookBlockOnlyMock
|
1028
|
+
|
1029
|
+
block_ran = false
|
1030
|
+
|
1031
|
+
ClusterModuleMock = ::Module.new
|
1032
|
+
ClusterModuleMock.module_eval do
|
1033
|
+
extend ::Module::Cluster
|
1034
|
+
block = ::Proc.new do |instance|
|
1035
|
+
block_ran = true
|
1036
|
+
end
|
1037
|
+
cluster( :cluster_name ).after_include_or_subclass( & block )
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
class BaseClassInclude
|
1041
|
+
include ClusterModuleMock
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
block_ran.should == true
|
1045
|
+
|
1046
|
+
block_ran = false
|
1047
|
+
|
1048
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
block_ran.should == true
|
1052
|
+
|
1053
|
+
block_ran = false
|
1054
|
+
|
1055
|
+
class BaseClassExtend
|
1056
|
+
extend ClusterModuleMock
|
1057
|
+
end
|
1058
|
+
|
1059
|
+
block_ran.should == false
|
1060
|
+
|
1061
|
+
block_ran = false
|
1062
|
+
|
1063
|
+
class BaseClassExtendSub < BaseClassExtend
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
block_ran.should == true
|
1067
|
+
|
1068
|
+
end
|
1069
|
+
end
|
1070
|
+
|
1071
|
+
it 'can simultaneously create hooks for both after-include and subclass - without block' do
|
1072
|
+
module ::Module::Cluster::AfterIncludeSubclassHookMock
|
1073
|
+
|
1074
|
+
module A
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
module ClusterModuleMock
|
1078
|
+
extend ::Module::Cluster
|
1079
|
+
cluster( :cluster_name ).after_include_or_subclass.extend( A )
|
1080
|
+
def self.included( instance )
|
1081
|
+
instance.is_a?( A ).should == false
|
1082
|
+
super if defined?( super )
|
1083
|
+
instance.is_a?( A ).should == true
|
1084
|
+
end
|
1085
|
+
def self.extended( instance )
|
1086
|
+
instance.is_a?( A ).should == false
|
1087
|
+
super if defined?( super )
|
1088
|
+
instance.is_a?( A ).should == false
|
1089
|
+
end
|
1090
|
+
end
|
1091
|
+
|
1092
|
+
class BaseClassInclude
|
1093
|
+
include ClusterModuleMock
|
1094
|
+
is_a?( A ).should == true
|
1095
|
+
def self.inherited( instance )
|
1096
|
+
instance.is_a?( A ).should == true
|
1097
|
+
super if defined?( super )
|
1098
|
+
instance.is_a?( A ).should == true
|
1099
|
+
end
|
1100
|
+
end
|
1101
|
+
|
1102
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1103
|
+
is_a?( A ).should == true
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
class BaseClassExtend
|
1107
|
+
extend ClusterModuleMock
|
1108
|
+
is_a?( A ).should == false
|
1109
|
+
def self.inherited( instance )
|
1110
|
+
instance.is_a?( A ).should == false
|
1111
|
+
super if defined?( super )
|
1112
|
+
instance.is_a?( A ).should == true
|
1113
|
+
end
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
class BaseClassExtendSub < BaseClassExtend
|
1117
|
+
is_a?( A ).should == true
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
end
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
it 'can simultaneously create hooks for both after-include and subclass - with block' do
|
1124
|
+
module ::Module::Cluster::AfterIncludeSubclassHookBlockMock
|
1125
|
+
|
1126
|
+
module A
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
block_ran = false
|
1130
|
+
|
1131
|
+
ClusterModuleMock = ::Module.new
|
1132
|
+
ClusterModuleMock.module_eval do
|
1133
|
+
extend ::Module::Cluster
|
1134
|
+
block = ::Proc.new do |instance|
|
1135
|
+
instance.is_a?( A ).should == true
|
1136
|
+
block_ran = true
|
1137
|
+
end
|
1138
|
+
cluster( :cluster_name ).after_include_or_subclass.extend( A, & block )
|
1139
|
+
def self.included( instance )
|
1140
|
+
instance.is_a?( A ).should == false
|
1141
|
+
super if defined?( super )
|
1142
|
+
instance.is_a?( A ).should == true
|
1143
|
+
end
|
1144
|
+
def self.extended( instance )
|
1145
|
+
instance.is_a?( A ).should == false
|
1146
|
+
super if defined?( super )
|
1147
|
+
end
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
class BaseClassInclude
|
1151
|
+
include ClusterModuleMock
|
1152
|
+
is_a?( A ).should == true
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
block_ran.should == true
|
1156
|
+
|
1157
|
+
block_ran = false
|
1158
|
+
|
1159
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1160
|
+
is_a?( A ).should == true
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
block_ran.should == true
|
1164
|
+
|
1165
|
+
block_ran = false
|
1166
|
+
|
1167
|
+
class BaseClassExtend
|
1168
|
+
extend ClusterModuleMock
|
1169
|
+
is_a?( A ).should == false
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
block_ran.should == false
|
1173
|
+
|
1174
|
+
block_ran = false
|
1175
|
+
|
1176
|
+
class BaseClassExtendSub < BaseClassExtend
|
1177
|
+
is_a?( A ).should == true
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
block_ran.should == true
|
1181
|
+
|
1182
|
+
end
|
1183
|
+
end
|
1184
|
+
|
1185
|
+
###############################
|
1186
|
+
# before_extend_or_subclass #
|
1187
|
+
###############################
|
1188
|
+
|
1189
|
+
it 'can simultaneously create hooks for both before-extend and subclass - with block only' do
|
1190
|
+
module ::Module::Cluster::BeforeExtendSubclassHookBlockOnlyMock
|
1191
|
+
|
1192
|
+
block_ran = false
|
1193
|
+
|
1194
|
+
ClusterModuleMock = ::Module.new
|
1195
|
+
ClusterModuleMock.module_eval do
|
1196
|
+
extend ::Module::Cluster
|
1197
|
+
block = ::Proc.new do |instance|
|
1198
|
+
block_ran = true
|
1199
|
+
end
|
1200
|
+
cluster( :cluster_name ).before_extend_or_subclass( & block )
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
class BaseClassInclude
|
1204
|
+
include ClusterModuleMock
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
block_ran.should == false
|
1208
|
+
|
1209
|
+
block_ran = false
|
1210
|
+
|
1211
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
block_ran.should == true
|
1215
|
+
|
1216
|
+
block_ran = false
|
1217
|
+
|
1218
|
+
class BaseClassExtend
|
1219
|
+
extend ClusterModuleMock
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
block_ran.should == true
|
1223
|
+
|
1224
|
+
block_ran = false
|
1225
|
+
|
1226
|
+
class BaseClassExtendSub < BaseClassExtend
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
block_ran.should == true
|
1230
|
+
|
1231
|
+
end
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
it 'can simultaneously create hooks for both before-extend and subclass - without block' do
|
1235
|
+
module ::Module::Cluster::BeforeExtendSubclassHookMock
|
1236
|
+
|
1237
|
+
module A
|
1238
|
+
end
|
1239
|
+
|
1240
|
+
module ClusterModuleMock
|
1241
|
+
extend ::Module::Cluster
|
1242
|
+
cluster( :cluster_name ).before_extend_or_subclass.extend( A )
|
1243
|
+
def self.included( instance )
|
1244
|
+
instance.is_a?( A ).should == false
|
1245
|
+
super if defined?( super )
|
1246
|
+
instance.is_a?( A ).should == false
|
1247
|
+
end
|
1248
|
+
def self.extended( instance )
|
1249
|
+
instance.is_a?( A ).should == true
|
1250
|
+
end
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
class BaseClassInclude
|
1254
|
+
include ClusterModuleMock
|
1255
|
+
is_a?( A ).should == false
|
1256
|
+
def self.inherited( instance )
|
1257
|
+
instance.is_a?( A ).should == false
|
1258
|
+
super if defined?( super )
|
1259
|
+
instance.is_a?( A ).should == true
|
1260
|
+
end
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1264
|
+
is_a?( A ).should == true
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
class BaseClassExtend
|
1268
|
+
extend ClusterModuleMock
|
1269
|
+
is_a?( A ).should == true
|
1270
|
+
def self.inherited( instance )
|
1271
|
+
instance.is_a?( A ).should == true
|
1272
|
+
super if defined?( super )
|
1273
|
+
end
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
class BaseClassExtendSub < BaseClassExtend
|
1277
|
+
is_a?( A ).should == true
|
1278
|
+
end
|
1279
|
+
|
1280
|
+
end
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
it 'can simultaneously create hooks for both before-extend and subclass - with block' do
|
1284
|
+
module ::Module::Cluster::BeforeExtendSubclassHookBlockMock
|
1285
|
+
|
1286
|
+
module A
|
1287
|
+
end
|
1288
|
+
|
1289
|
+
block_ran = false
|
1290
|
+
|
1291
|
+
ClusterModuleMock = ::Module.new
|
1292
|
+
ClusterModuleMock.module_eval do
|
1293
|
+
extend ::Module::Cluster
|
1294
|
+
block = ::Proc.new do |instance|
|
1295
|
+
instance.is_a?( A ).should == true
|
1296
|
+
block_ran = true
|
1297
|
+
end
|
1298
|
+
cluster( :cluster_name ).before_extend_or_subclass.extend( A, & block )
|
1299
|
+
def self.included( instance )
|
1300
|
+
instance.is_a?( A ).should == false
|
1301
|
+
super if defined?( super )
|
1302
|
+
end
|
1303
|
+
def self.extended( instance )
|
1304
|
+
instance.is_a?( A ).should == true
|
1305
|
+
super if defined?( super )
|
1306
|
+
instance.is_a?( A ).should == true
|
1307
|
+
end
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
class BaseClassInclude
|
1311
|
+
include ClusterModuleMock
|
1312
|
+
is_a?( A ).should == false
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
block_ran.should == false
|
1316
|
+
|
1317
|
+
block_ran = false
|
1318
|
+
|
1319
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1320
|
+
is_a?( A ).should == true
|
1321
|
+
end
|
1322
|
+
|
1323
|
+
block_ran.should == true
|
1324
|
+
|
1325
|
+
block_ran = false
|
1326
|
+
|
1327
|
+
class BaseClassExtend
|
1328
|
+
extend ClusterModuleMock
|
1329
|
+
is_a?( A ).should == true
|
1330
|
+
end
|
1331
|
+
|
1332
|
+
block_ran.should == true
|
1333
|
+
|
1334
|
+
block_ran = false
|
1335
|
+
|
1336
|
+
class BaseClassExtendSub < BaseClassExtend
|
1337
|
+
is_a?( A ).should == true
|
1338
|
+
end
|
1339
|
+
|
1340
|
+
block_ran.should == true
|
1341
|
+
|
1342
|
+
end
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
##############################
|
1346
|
+
# after_extend_or_subclass #
|
1347
|
+
##############################
|
1348
|
+
|
1349
|
+
it 'can simultaneously create hooks for both after-extend and subclass - with block only' do
|
1350
|
+
module ::Module::Cluster::AfterExtendSubclassHookBlockOnlyMock
|
1351
|
+
|
1352
|
+
block_ran = false
|
1353
|
+
|
1354
|
+
ClusterModuleMock = ::Module.new
|
1355
|
+
ClusterModuleMock.module_eval do
|
1356
|
+
extend ::Module::Cluster
|
1357
|
+
block = ::Proc.new do |instance|
|
1358
|
+
block_ran = true
|
1359
|
+
end
|
1360
|
+
cluster( :cluster_name ).after_extend_or_subclass( & block )
|
1361
|
+
end
|
1362
|
+
|
1363
|
+
class BaseClassInclude
|
1364
|
+
include ClusterModuleMock
|
1365
|
+
end
|
1366
|
+
|
1367
|
+
block_ran.should == false
|
1368
|
+
|
1369
|
+
block_ran = false
|
1370
|
+
|
1371
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1372
|
+
end
|
1373
|
+
|
1374
|
+
block_ran.should == true
|
1375
|
+
|
1376
|
+
block_ran = false
|
1377
|
+
|
1378
|
+
class BaseClassExtend
|
1379
|
+
extend ClusterModuleMock
|
1380
|
+
end
|
1381
|
+
|
1382
|
+
block_ran.should == true
|
1383
|
+
|
1384
|
+
block_ran = false
|
1385
|
+
|
1386
|
+
class BaseClassExtendSub < BaseClassExtend
|
1387
|
+
end
|
1388
|
+
|
1389
|
+
block_ran.should == true
|
1390
|
+
|
1391
|
+
end
|
1392
|
+
end
|
1393
|
+
|
1394
|
+
it 'can simultaneously create hooks for both after-extend and subclass - without block' do
|
1395
|
+
module ::Module::Cluster::AfterExtendSubclassHookMock
|
1396
|
+
|
1397
|
+
module A
|
1398
|
+
end
|
1399
|
+
|
1400
|
+
module ClusterModuleMock
|
1401
|
+
extend ::Module::Cluster
|
1402
|
+
cluster( :cluster_name ).after_extend_or_subclass.extend( A )
|
1403
|
+
def self.included( instance )
|
1404
|
+
instance.is_a?( A ).should == false
|
1405
|
+
super if defined?( super )
|
1406
|
+
instance.is_a?( A ).should == false
|
1407
|
+
end
|
1408
|
+
def self.extended( instance )
|
1409
|
+
instance.is_a?( A ).should == false
|
1410
|
+
super if defined?( super )
|
1411
|
+
instance.is_a?( A ).should == true
|
1412
|
+
end
|
1413
|
+
end
|
1414
|
+
|
1415
|
+
class BaseClassInclude
|
1416
|
+
include ClusterModuleMock
|
1417
|
+
is_a?( A ).should == false
|
1418
|
+
def self.inherited( instance )
|
1419
|
+
instance.is_a?( A ).should == false
|
1420
|
+
super if defined?( super )
|
1421
|
+
instance.is_a?( A ).should == true
|
1422
|
+
end
|
1423
|
+
end
|
1424
|
+
|
1425
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1426
|
+
is_a?( A ).should == true
|
1427
|
+
end
|
1428
|
+
|
1429
|
+
class BaseClassExtend
|
1430
|
+
extend ClusterModuleMock
|
1431
|
+
is_a?( A ).should == true
|
1432
|
+
def self.inherited( instance )
|
1433
|
+
instance.is_a?( A ).should == true
|
1434
|
+
super if defined?( super )
|
1435
|
+
end
|
1436
|
+
end
|
1437
|
+
|
1438
|
+
class BaseClassExtendSub < BaseClassExtend
|
1439
|
+
is_a?( A ).should == true
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
end
|
1443
|
+
end
|
1444
|
+
|
1445
|
+
it 'can simultaneously create hooks for both after-extend and subclass - with block' do
|
1446
|
+
module ::Module::Cluster::AfterExtendSubclassHookBlockMock
|
1447
|
+
|
1448
|
+
module A
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
block_ran = false
|
1452
|
+
|
1453
|
+
ClusterModuleMock = ::Module.new
|
1454
|
+
ClusterModuleMock.module_eval do
|
1455
|
+
extend ::Module::Cluster
|
1456
|
+
block = ::Proc.new do |instance|
|
1457
|
+
instance.is_a?( A ).should == true
|
1458
|
+
block_ran = true
|
1459
|
+
end
|
1460
|
+
cluster( :cluster_name ).after_extend_or_subclass.extend( A, & block )
|
1461
|
+
def self.included( instance )
|
1462
|
+
instance.is_a?( A ).should == false
|
1463
|
+
super if defined?( super )
|
1464
|
+
end
|
1465
|
+
def self.extended( instance )
|
1466
|
+
instance.is_a?( A ).should == false
|
1467
|
+
super if defined?( super )
|
1468
|
+
instance.is_a?( A ).should == true
|
1469
|
+
end
|
1470
|
+
end
|
1471
|
+
|
1472
|
+
class BaseClassInclude
|
1473
|
+
include ClusterModuleMock
|
1474
|
+
is_a?( A ).should == false
|
1475
|
+
end
|
1476
|
+
|
1477
|
+
block_ran.should == false
|
1478
|
+
|
1479
|
+
block_ran = false
|
1480
|
+
|
1481
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1482
|
+
is_a?( A ).should == true
|
1483
|
+
end
|
1484
|
+
|
1485
|
+
block_ran.should == true
|
1486
|
+
|
1487
|
+
block_ran = false
|
1488
|
+
|
1489
|
+
class BaseClassExtend
|
1490
|
+
extend ClusterModuleMock
|
1491
|
+
is_a?( A ).should == true
|
1492
|
+
end
|
1493
|
+
|
1494
|
+
block_ran.should == true
|
1495
|
+
|
1496
|
+
block_ran = false
|
1497
|
+
|
1498
|
+
class BaseClassExtendSub < BaseClassExtend
|
1499
|
+
is_a?( A ).should == true
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
block_ran.should == true
|
1503
|
+
|
1504
|
+
end
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
##########################################
|
1508
|
+
# before_include_or_extend_or_subclass #
|
1509
|
+
##########################################
|
1510
|
+
|
1511
|
+
it 'can simultaneously create hooks for before-extend, before-include, and subclass - with block only' do
|
1512
|
+
module ::Module::Cluster::BeforeIncludeExtendSubclassHookBlockOnlyMock
|
1513
|
+
|
1514
|
+
block_ran = false
|
1515
|
+
|
1516
|
+
ClusterModuleMock = ::Module.new
|
1517
|
+
ClusterModuleMock.module_eval do
|
1518
|
+
extend ::Module::Cluster
|
1519
|
+
block = ::Proc.new do |instance|
|
1520
|
+
block_ran = true
|
1521
|
+
end
|
1522
|
+
cluster( :cluster_name ).before_include_or_extend_or_subclass( & block )
|
1523
|
+
end
|
1524
|
+
|
1525
|
+
class BaseClassInclude
|
1526
|
+
include ClusterModuleMock
|
1527
|
+
end
|
1528
|
+
|
1529
|
+
block_ran.should == true
|
1530
|
+
|
1531
|
+
block_ran = false
|
1532
|
+
|
1533
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1534
|
+
end
|
1535
|
+
|
1536
|
+
block_ran.should == true
|
1537
|
+
|
1538
|
+
block_ran = false
|
1539
|
+
|
1540
|
+
class BaseClassExtend
|
1541
|
+
extend ClusterModuleMock
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
block_ran.should == true
|
1545
|
+
|
1546
|
+
block_ran = false
|
1547
|
+
|
1548
|
+
class BaseClassExtendSub < BaseClassExtend
|
1549
|
+
end
|
1550
|
+
|
1551
|
+
block_ran.should == true
|
1552
|
+
|
1553
|
+
end
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
it 'can simultaneously create hooks for before-extend, before-include, and subclass - without block' do
|
1557
|
+
module ::Module::Cluster::BeforeIncludeExtendSubclassHookMock
|
1558
|
+
|
1559
|
+
module A
|
1560
|
+
end
|
1561
|
+
|
1562
|
+
module ClusterModuleMock
|
1563
|
+
extend ::Module::Cluster
|
1564
|
+
cluster( :cluster_name ).before_include_or_extend_or_subclass.extend( A )
|
1565
|
+
def self.included( instance )
|
1566
|
+
instance.is_a?( A ).should == true
|
1567
|
+
super if defined?( super )
|
1568
|
+
end
|
1569
|
+
def self.extended( instance )
|
1570
|
+
instance.is_a?( A ).should == true
|
1571
|
+
super if defined?( super )
|
1572
|
+
end
|
1573
|
+
end
|
1574
|
+
|
1575
|
+
class BaseClassInclude
|
1576
|
+
include ClusterModuleMock
|
1577
|
+
is_a?( A ).should == true
|
1578
|
+
def self.inherited( instance )
|
1579
|
+
instance.is_a?( A ).should == true
|
1580
|
+
super if defined?( super )
|
1581
|
+
instance.is_a?( A ).should == true
|
1582
|
+
end
|
1583
|
+
end
|
1584
|
+
|
1585
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1586
|
+
is_a?( A ).should == true
|
1587
|
+
end
|
1588
|
+
|
1589
|
+
class BaseClassExtend
|
1590
|
+
extend ClusterModuleMock
|
1591
|
+
is_a?( A ).should == true
|
1592
|
+
def self.inherited( instance )
|
1593
|
+
instance.is_a?( A ).should == true
|
1594
|
+
super if defined?( super )
|
1595
|
+
end
|
1596
|
+
end
|
1597
|
+
|
1598
|
+
class BaseClassExtendSub < BaseClassExtend
|
1599
|
+
is_a?( A ).should == true
|
1600
|
+
end
|
1601
|
+
|
1602
|
+
end
|
1603
|
+
end
|
1604
|
+
|
1605
|
+
it 'can simultaneously create hooks for before-extend, before-include, and subclass - with block' do
|
1606
|
+
module ::Module::Cluster::BeforeIncludeExtendSubclassHookBlockMock
|
1607
|
+
|
1608
|
+
module A
|
1609
|
+
end
|
1610
|
+
|
1611
|
+
block_ran = false
|
1612
|
+
|
1613
|
+
ClusterModuleMock = ::Module.new
|
1614
|
+
ClusterModuleMock.module_eval do
|
1615
|
+
extend ::Module::Cluster
|
1616
|
+
block = ::Proc.new do |instance|
|
1617
|
+
instance.is_a?( A ).should == true
|
1618
|
+
block_ran = true
|
1619
|
+
end
|
1620
|
+
cluster( :cluster_name ).before_include_or_extend_or_subclass.extend( A, & block )
|
1621
|
+
def self.included( instance )
|
1622
|
+
instance.is_a?( A ).should == true
|
1623
|
+
super if defined?( super )
|
1624
|
+
instance.is_a?( A ).should == true
|
1625
|
+
end
|
1626
|
+
def self.extended( instance )
|
1627
|
+
instance.is_a?( A ).should == true
|
1628
|
+
super if defined?( super )
|
1629
|
+
instance.is_a?( A ).should == true
|
1630
|
+
end
|
1631
|
+
end
|
1632
|
+
|
1633
|
+
class BaseClassInclude
|
1634
|
+
include ClusterModuleMock
|
1635
|
+
is_a?( A ).should == true
|
1636
|
+
end
|
1637
|
+
|
1638
|
+
block_ran.should == true
|
1639
|
+
|
1640
|
+
block_ran = false
|
1641
|
+
|
1642
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1643
|
+
is_a?( A ).should == true
|
1644
|
+
end
|
1645
|
+
|
1646
|
+
block_ran.should == true
|
1647
|
+
|
1648
|
+
block_ran = false
|
1649
|
+
|
1650
|
+
class BaseClassExtend
|
1651
|
+
extend ClusterModuleMock
|
1652
|
+
is_a?( A ).should == true
|
1653
|
+
end
|
1654
|
+
|
1655
|
+
block_ran.should == true
|
1656
|
+
|
1657
|
+
block_ran = false
|
1658
|
+
|
1659
|
+
class BaseClassExtendSub < BaseClassExtend
|
1660
|
+
is_a?( A ).should == true
|
1661
|
+
end
|
1662
|
+
|
1663
|
+
block_ran.should == true
|
1664
|
+
|
1665
|
+
end
|
1666
|
+
end
|
1667
|
+
|
1668
|
+
#########################################
|
1669
|
+
# after_include_or_extend_or_subclass #
|
1670
|
+
#########################################
|
1671
|
+
|
1672
|
+
it 'can simultaneously create hooks for after-extend, after-include, and subclass - with block only' do
|
1673
|
+
module ::Module::Cluster::AfterIncludeExtendSubclassHookBlockOnlyMock
|
1674
|
+
|
1675
|
+
block_ran = false
|
1676
|
+
|
1677
|
+
ClusterModuleMock = ::Module.new
|
1678
|
+
ClusterModuleMock.module_eval do
|
1679
|
+
extend ::Module::Cluster
|
1680
|
+
block = ::Proc.new do |instance|
|
1681
|
+
block_ran = true
|
1682
|
+
end
|
1683
|
+
cluster( :cluster_name ).after_include_or_extend_or_subclass( & block )
|
1684
|
+
end
|
1685
|
+
|
1686
|
+
class BaseClassInclude
|
1687
|
+
include ClusterModuleMock
|
1688
|
+
end
|
1689
|
+
|
1690
|
+
block_ran.should == true
|
1691
|
+
|
1692
|
+
block_ran = false
|
1693
|
+
|
1694
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1695
|
+
end
|
1696
|
+
|
1697
|
+
block_ran.should == true
|
1698
|
+
|
1699
|
+
block_ran = false
|
1700
|
+
|
1701
|
+
class BaseClassExtend
|
1702
|
+
extend ClusterModuleMock
|
1703
|
+
end
|
1704
|
+
|
1705
|
+
block_ran.should == true
|
1706
|
+
|
1707
|
+
block_ran = false
|
1708
|
+
|
1709
|
+
class BaseClassExtendSub < BaseClassExtend
|
1710
|
+
end
|
1711
|
+
|
1712
|
+
block_ran.should == true
|
1713
|
+
|
1714
|
+
end
|
1715
|
+
end
|
1716
|
+
|
1717
|
+
it 'can simultaneously create hooks for after-extend, after-include, and subclass - without block' do
|
1718
|
+
module ::Module::Cluster::AfterIncludeExtendSubclassHookMock
|
1719
|
+
|
1720
|
+
module A
|
1721
|
+
end
|
1722
|
+
|
1723
|
+
module ClusterModuleMock
|
1724
|
+
extend ::Module::Cluster
|
1725
|
+
cluster( :cluster_name ).after_include_or_extend_or_subclass.extend( A )
|
1726
|
+
def self.included( instance )
|
1727
|
+
instance.is_a?( A ).should == false
|
1728
|
+
super if defined?( super )
|
1729
|
+
instance.is_a?( A ).should == true
|
1730
|
+
end
|
1731
|
+
def self.extended( instance )
|
1732
|
+
instance.is_a?( A ).should == false
|
1733
|
+
super if defined?( super )
|
1734
|
+
instance.is_a?( A ).should == true
|
1735
|
+
end
|
1736
|
+
end
|
1737
|
+
|
1738
|
+
class BaseClassInclude
|
1739
|
+
include ClusterModuleMock
|
1740
|
+
is_a?( A ).should == true
|
1741
|
+
def self.inherited( instance )
|
1742
|
+
instance.is_a?( A ).should == true
|
1743
|
+
super if defined?( super )
|
1744
|
+
instance.is_a?( A ).should == true
|
1745
|
+
end
|
1746
|
+
end
|
1747
|
+
|
1748
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1749
|
+
is_a?( A ).should == true
|
1750
|
+
end
|
1751
|
+
|
1752
|
+
class BaseClassExtend
|
1753
|
+
extend ClusterModuleMock
|
1754
|
+
is_a?( A ).should == true
|
1755
|
+
def self.inherited( instance )
|
1756
|
+
instance.is_a?( A ).should == true
|
1757
|
+
super if defined?( super )
|
1758
|
+
end
|
1759
|
+
end
|
1760
|
+
|
1761
|
+
class BaseClassExtendSub < BaseClassExtend
|
1762
|
+
is_a?( A ).should == true
|
1763
|
+
end
|
1764
|
+
|
1765
|
+
end
|
1766
|
+
end
|
1767
|
+
|
1768
|
+
it 'can simultaneously create hooks for after-extend, after-include, and subclass - with block' do
|
1769
|
+
module ::Module::Cluster::AfterIncludeExtendSubclassHookBlockMock
|
1770
|
+
|
1771
|
+
module A
|
1772
|
+
end
|
1773
|
+
|
1774
|
+
block_ran = false
|
1775
|
+
|
1776
|
+
ClusterModuleMock = ::Module.new
|
1777
|
+
ClusterModuleMock.module_eval do
|
1778
|
+
extend ::Module::Cluster
|
1779
|
+
block = ::Proc.new do |instance|
|
1780
|
+
instance.is_a?( A ).should == true
|
1781
|
+
block_ran = true
|
1782
|
+
end
|
1783
|
+
cluster( :cluster_name ).after_include_or_extend_or_subclass.extend( A, & block )
|
1784
|
+
def self.included( instance )
|
1785
|
+
instance.is_a?( A ).should == false
|
1786
|
+
super if defined?( super )
|
1787
|
+
instance.is_a?( A ).should == true
|
1788
|
+
end
|
1789
|
+
def self.extended( instance )
|
1790
|
+
instance.is_a?( A ).should == false
|
1791
|
+
super if defined?( super )
|
1792
|
+
instance.is_a?( A ).should == true
|
1793
|
+
end
|
1794
|
+
end
|
1795
|
+
|
1796
|
+
class BaseClassInclude
|
1797
|
+
include ClusterModuleMock
|
1798
|
+
is_a?( A ).should == true
|
1799
|
+
end
|
1800
|
+
|
1801
|
+
block_ran.should == true
|
1802
|
+
|
1803
|
+
block_ran = false
|
1804
|
+
|
1805
|
+
class BaseClassIncludeSub < BaseClassInclude
|
1806
|
+
is_a?( A ).should == true
|
1807
|
+
end
|
1808
|
+
|
1809
|
+
block_ran.should == true
|
1810
|
+
|
1811
|
+
block_ran = false
|
1812
|
+
|
1813
|
+
class BaseClassExtend
|
1814
|
+
extend ClusterModuleMock
|
1815
|
+
is_a?( A ).should == true
|
1816
|
+
end
|
1817
|
+
|
1818
|
+
block_ran.should == true
|
1819
|
+
|
1820
|
+
block_ran = false
|
1821
|
+
|
1822
|
+
class BaseClassExtendSub < BaseClassExtend
|
1823
|
+
is_a?( A ).should == true
|
1824
|
+
end
|
1825
|
+
|
1826
|
+
block_ran.should == true
|
1827
|
+
|
1828
|
+
end
|
1829
|
+
end
|
1830
|
+
|
636
1831
|
#######################
|
637
1832
|
# conditional hooks #
|
638
1833
|
#######################
|