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.
- data/README.md +127 -337
- data/lib/module-cluster.rb +1 -153
- data/lib/module/cluster.rb +341 -0
- data/lib/module/cluster/class_support.rb +22 -0
- data/lib/module/cluster/cluster.rb +10 -0
- data/lib/module/cluster/cluster/cluster_interface.rb +550 -0
- data/lib/module/cluster/exception/module_not_in_stack.rb +26 -0
- data/lib/module/cluster/instance_controller.rb +14 -0
- data/lib/module/cluster/instance_controller/hook_controller.rb +33 -0
- data/lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb +511 -0
- data/lib/module/cluster/instance_controller/hook_controller/hook_controller_interface.rb +830 -0
- data/lib/module/cluster/instance_controller/instance_controller_interface.rb +269 -0
- data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy.rb +359 -0
- data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy/chain_proxy.rb +442 -0
- data/lib/module/cluster/module_support.rb +67 -0
- data/lib/module/namespaces.rb +13 -0
- data/lib/module/requires.rb +32 -0
- data/spec/module/cluster/cluster_spec.rb +473 -0
- data/spec/module/cluster/instance_controller/hook_controller_spec.rb +922 -0
- data/spec/module/cluster/instance_controller/multiple_hook_controller_proxy_spec.rb +1240 -0
- data/spec/module/cluster_spec.rb +1794 -0
- metadata +27 -98
- data/README.rdoc +0 -395
- data/lib/module-cluster/ModuleCluster.rb +0 -9
- data/lib/module-cluster/ModuleCluster/Define.rb +0 -12
- data/lib/module-cluster/ModuleCluster/Define/Block.rb +0 -9
- data/lib/module-cluster/ModuleCluster/Define/Block/CascadingClass.rb +0 -83
- data/lib/module-cluster/ModuleCluster/Define/Block/CascadingClassOrModule.rb +0 -70
- data/lib/module-cluster/ModuleCluster/Define/Block/CascadingModule.rb +0 -79
- data/lib/module-cluster/ModuleCluster/Define/Block/CascadingModuleOrSubclass.rb +0 -21
- data/lib/module-cluster/ModuleCluster/Define/Block/Class.rb +0 -77
- data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb +0 -78
- data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModule.rb +0 -78
- data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrInstance.rb +0 -78
- data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrSubclass.rb +0 -36
- data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrSubclass.rb +0 -29
- data/lib/module-cluster/ModuleCluster/Define/Block/Instance.rb +0 -45
- data/lib/module-cluster/ModuleCluster/Define/Block/Module.rb +0 -77
- data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb +0 -78
- data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrSubclass.rb +0 -29
- data/lib/module-cluster/ModuleCluster/Define/Block/Subclass.rb +0 -56
- data/lib/module-cluster/ModuleCluster/Define/ClassCluster.rb +0 -193
- data/lib/module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb +0 -128
- data/lib/module-cluster/ModuleCluster/Define/Cluster.rb +0 -181
- data/lib/module-cluster/ModuleCluster/Define/ClusterCascades.rb +0 -185
- data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb +0 -181
- data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb +0 -181
- data/lib/module-cluster/ModuleCluster/Define/Deprecated.rb +0 -40
- data/lib/module-cluster/ModuleCluster/Define/InstanceCluster.rb +0 -45
- data/lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb +0 -193
- data/lib/module-cluster/ModuleCluster/Define/ModuleOrClassCluster.rb +0 -209
- data/lib/module-cluster/ModuleCluster/Define/ModuleOrInstanceCluster.rb +0 -128
- data/lib/module-cluster/ModuleCluster/Define/Status.rb +0 -106
- data/lib/module-cluster/ModuleCluster/Suspend.rb +0 -7
- data/lib/module-cluster/ModuleCluster/Suspend/Hooks.rb +0 -315
- data/lib/module-cluster/ModuleCluster/Suspend/WithoutHooks.rb +0 -153
- data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures.rb +0 -77
- data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb +0 -44
- data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb +0 -292
- data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclass.rb +0 -24
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack.rb +0 -12
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block.rb +0 -9
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb +0 -36
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Inherited.rb +0 -20
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb +0 -20
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb +0 -36
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb +0 -6
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb +0 -140
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Includes.rb +0 -110
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb +0 -140
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb +0 -110
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb +0 -35
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy.rb +0 -359
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Status.rb +0 -55
- data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Suspend.rb +0 -199
- data/lib/module-cluster/_private_/ModuleCluster/ExtendForCascade.rb +0 -34
- data/spec/ModuleCluster/Define/Block/CascadingClassOrModule_spec.rb +0 -285
- data/spec/ModuleCluster/Define/Block/CascadingClass_spec.rb +0 -254
- data/spec/ModuleCluster/Define/Block/CascadingModuleOrSubclass_spec.rb +0 -56
- data/spec/ModuleCluster/Define/Block/CascadingModule_spec.rb +0 -278
- data/spec/ModuleCluster/Define/Block/ClassOrInstance_spec.rb +0 -230
- data/spec/ModuleCluster/Define/Block/ClassOrModuleOrInstance_spec.rb +0 -238
- data/spec/ModuleCluster/Define/Block/ClassOrModuleOrSubclass_spec.rb +0 -54
- data/spec/ModuleCluster/Define/Block/ClassOrModule_spec.rb +0 -231
- data/spec/ModuleCluster/Define/Block/ClassOrSubclass_spec.rb +0 -54
- data/spec/ModuleCluster/Define/Block/Class_spec.rb +0 -224
- data/spec/ModuleCluster/Define/Block/Instance_spec.rb +0 -78
- data/spec/ModuleCluster/Define/Block/ModuleOrInstance_spec.rb +0 -54
- data/spec/ModuleCluster/Define/Block/ModuleOrSubclass_spec.rb +0 -51
- data/spec/ModuleCluster/Define/Block/Module_spec.rb +0 -230
- data/spec/ModuleCluster/Define/Block/Subclass_spec.rb +0 -73
- data/spec/ModuleCluster/Define/Block_spec.rb +0 -18
- data/spec/ModuleCluster/Define/ClassCluster_spec.rb +0 -728
- data/spec/ModuleCluster/Define/ClassOrInstanceCluster_spec.rb +0 -576
- data/spec/ModuleCluster/Define/ClusterCascadesToClass_spec.rb +0 -659
- data/spec/ModuleCluster/Define/ClusterCascadesToModule_spec.rb +0 -678
- data/spec/ModuleCluster/Define/ClusterCascades_spec.rb +0 -644
- data/spec/ModuleCluster/Define/Cluster_spec.rb +0 -708
- data/spec/ModuleCluster/Define/InstanceCluster_spec.rb +0 -102
- data/spec/ModuleCluster/Define/ModuleCluster_spec.rb +0 -728
- data/spec/ModuleCluster/Define/ModuleOrClassCluster_spec.rb +0 -728
- data/spec/ModuleCluster/Define/ModuleOrInstanceCluster_spec.rb +0 -576
- data/spec/ModuleCluster/Suspend/Hooks_spec.rb +0 -573
- data/spec/ModuleCluster/Suspend/WithoutHooks_spec.rb +0 -559
- data/spec/ModuleCluster_spec.rb +0 -15
- data/spec/_private_/ModuleCluster/CascadeFeatures/PerformCascades_spec.rb +0 -386
- data/spec/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy_spec.rb +0 -419
- data/spec/_private_/ModuleCluster/ClusterStack/Suspend_spec.rb +0 -242
@@ -0,0 +1,922 @@
|
|
1
|
+
|
2
|
+
require_relative '../../../../lib/module/cluster.rb'
|
3
|
+
|
4
|
+
describe ::Module::Cluster::InstanceController::HookController do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
module ::Module::Cluster::InstanceController::HookController::Mock
|
8
|
+
|
9
|
+
module Instance
|
10
|
+
end
|
11
|
+
|
12
|
+
class InstanceControllerMock
|
13
|
+
def instance
|
14
|
+
return Instance
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
InstanceController = InstanceControllerMock.new
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
################
|
24
|
+
# initialize #
|
25
|
+
# stack #
|
26
|
+
################
|
27
|
+
|
28
|
+
it 'can initialize for a parent instance controller' do
|
29
|
+
module ::Module::Cluster::InstanceController::HookController::InitializeMock
|
30
|
+
|
31
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
32
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
33
|
+
|
34
|
+
hook_controller.instance_variable_get( :@parent_instance_controller ).should == instance_controller
|
35
|
+
hook_controller.stack.is_a?( ::Array ).should == true
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
#############
|
41
|
+
# include #
|
42
|
+
#############
|
43
|
+
|
44
|
+
it 'can put modules on its stack for including at later event hook' do
|
45
|
+
module ::Module::Cluster::InstanceController::HookController::IncludeMock
|
46
|
+
|
47
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
48
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
49
|
+
|
50
|
+
module A
|
51
|
+
end
|
52
|
+
module B
|
53
|
+
end
|
54
|
+
module C
|
55
|
+
end
|
56
|
+
|
57
|
+
hook_controller.include( A, B, C )
|
58
|
+
|
59
|
+
hook_controller.stack[ 0 ].module.should == A
|
60
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
61
|
+
hook_controller.stack[ 0 ].action.should == :include
|
62
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
63
|
+
hook_controller.stack[ 0 ].block.should == nil
|
64
|
+
|
65
|
+
hook_controller.stack[ 1 ].module.should == B
|
66
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
67
|
+
hook_controller.stack[ 1 ].action.should == :include
|
68
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
69
|
+
hook_controller.stack[ 1 ].block.should == nil
|
70
|
+
|
71
|
+
hook_controller.stack[ 2 ].module.should == C
|
72
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
73
|
+
hook_controller.stack[ 2 ].action.should == :include
|
74
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
75
|
+
hook_controller.stack[ 2 ].block.should == nil
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
############
|
81
|
+
# extend #
|
82
|
+
############
|
83
|
+
|
84
|
+
it 'can put modules on its stack for extending at later event hook' do
|
85
|
+
module ::Module::Cluster::InstanceController::HookController::ExtendMock
|
86
|
+
|
87
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
88
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
89
|
+
|
90
|
+
module A
|
91
|
+
end
|
92
|
+
module B
|
93
|
+
end
|
94
|
+
module C
|
95
|
+
end
|
96
|
+
|
97
|
+
hook_controller.extend( A, B, C )
|
98
|
+
|
99
|
+
hook_controller.stack[ 0 ].module.should == A
|
100
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
101
|
+
hook_controller.stack[ 0 ].action.should == :extend
|
102
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
103
|
+
hook_controller.stack[ 0 ].block.should == nil
|
104
|
+
|
105
|
+
hook_controller.stack[ 1 ].module.should == B
|
106
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
107
|
+
hook_controller.stack[ 1 ].action.should == :extend
|
108
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
109
|
+
hook_controller.stack[ 1 ].block.should == nil
|
110
|
+
|
111
|
+
hook_controller.stack[ 2 ].module.should == C
|
112
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
113
|
+
hook_controller.stack[ 2 ].action.should == :extend
|
114
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
115
|
+
hook_controller.stack[ 2 ].block.should == nil
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
########################
|
121
|
+
# include_and_extend #
|
122
|
+
########################
|
123
|
+
|
124
|
+
it 'can put modules on its stack for including and extending at later event hook' do
|
125
|
+
module ::Module::Cluster::InstanceController::HookController::IncludeAndExtendMock
|
126
|
+
|
127
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
128
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
129
|
+
|
130
|
+
module A
|
131
|
+
end
|
132
|
+
module B
|
133
|
+
end
|
134
|
+
module C
|
135
|
+
end
|
136
|
+
|
137
|
+
hook_controller.include_and_extend( A, B, C )
|
138
|
+
|
139
|
+
# A
|
140
|
+
|
141
|
+
hook_controller.stack[ 0 ].module.should == A
|
142
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
143
|
+
hook_controller.stack[ 0 ].action.should == :include
|
144
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
145
|
+
hook_controller.stack[ 0 ].block.should == nil
|
146
|
+
|
147
|
+
hook_controller.stack[ 1 ].module.should == A
|
148
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
149
|
+
hook_controller.stack[ 1 ].action.should == :extend
|
150
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
151
|
+
hook_controller.stack[ 1 ].block.should == nil
|
152
|
+
|
153
|
+
# B
|
154
|
+
|
155
|
+
hook_controller.stack[ 2 ].module.should == B
|
156
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
157
|
+
hook_controller.stack[ 2 ].action.should == :include
|
158
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
159
|
+
hook_controller.stack[ 2 ].block.should == nil
|
160
|
+
|
161
|
+
hook_controller.stack[ 3 ].module.should == B
|
162
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
163
|
+
hook_controller.stack[ 3 ].action.should == :extend
|
164
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
165
|
+
hook_controller.stack[ 3 ].block.should == nil
|
166
|
+
|
167
|
+
# C
|
168
|
+
|
169
|
+
hook_controller.stack[ 4 ].module.should == C
|
170
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
171
|
+
hook_controller.stack[ 4 ].action.should == :include
|
172
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
173
|
+
hook_controller.stack[ 4 ].block.should == nil
|
174
|
+
|
175
|
+
hook_controller.stack[ 5 ].module.should == C
|
176
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
177
|
+
hook_controller.stack[ 5 ].action.should == :extend
|
178
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
179
|
+
hook_controller.stack[ 5 ].block.should == nil
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
##################################################################################################
|
185
|
+
# private ######################################################################################
|
186
|
+
##################################################################################################
|
187
|
+
|
188
|
+
|
189
|
+
#############
|
190
|
+
# indexes #
|
191
|
+
#############
|
192
|
+
|
193
|
+
it 'can return indexes corresponding to include actions on event stack' do
|
194
|
+
rspec = self
|
195
|
+
::Module::Cluster::InstanceController::HookController::IndexesMock = ::Module.new
|
196
|
+
::Module::Cluster::InstanceController::HookController::IndexesMock.module_eval do
|
197
|
+
|
198
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
199
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
200
|
+
|
201
|
+
module A
|
202
|
+
end
|
203
|
+
module B
|
204
|
+
end
|
205
|
+
module C
|
206
|
+
end
|
207
|
+
module D
|
208
|
+
end
|
209
|
+
module E
|
210
|
+
end
|
211
|
+
module F
|
212
|
+
end
|
213
|
+
|
214
|
+
hook_controller.include( A, B ).extend( C, D ).include( E ).extend( F ).instance_eval do
|
215
|
+
|
216
|
+
indexes( :include, A, B ).should == [ 0, 1 ]
|
217
|
+
indexes( :include, E, B ).should == [ 1, 4 ]
|
218
|
+
indexes( :include, E ).should == [ 4 ]
|
219
|
+
indexes( :extend, C, D ).should == [ 2, 3 ]
|
220
|
+
indexes( :extend, D ).should == [ 3 ]
|
221
|
+
indexes( :extend, F ).should == [ 5 ]
|
222
|
+
|
223
|
+
::Proc.new { indexes( :include, C ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
224
|
+
::Proc.new { indexes( :include, A, B, C ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
225
|
+
::Proc.new { indexes( :extend, A, B ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
226
|
+
::Proc.new { indexes( :extend, E ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
##################
|
234
|
+
# lowest_index #
|
235
|
+
##################
|
236
|
+
|
237
|
+
it 'can return the highest index for provided modules; throws exception if module provided is not found in stack' do
|
238
|
+
rspec = self
|
239
|
+
::Module::Cluster::InstanceController::HookController::LowestIndexMock = ::Module.new
|
240
|
+
::Module::Cluster::InstanceController::HookController::LowestIndexMock.module_eval do
|
241
|
+
|
242
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
243
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
244
|
+
|
245
|
+
module A
|
246
|
+
end
|
247
|
+
module B
|
248
|
+
end
|
249
|
+
module C
|
250
|
+
end
|
251
|
+
module D
|
252
|
+
end
|
253
|
+
module E
|
254
|
+
end
|
255
|
+
module F
|
256
|
+
end
|
257
|
+
|
258
|
+
hook_controller.include( A, B ).extend( C, D ).include( E ).extend( F ).instance_eval do
|
259
|
+
|
260
|
+
lowest_index( :include, A, B ).should == 0
|
261
|
+
lowest_index( :include, E, B ).should == 1
|
262
|
+
lowest_index( :include, E ).should == 4
|
263
|
+
lowest_index( :extend, D, C ).should == 2
|
264
|
+
lowest_index( :extend, D ).should == 3
|
265
|
+
lowest_index( :extend, F ).should == 5
|
266
|
+
|
267
|
+
::Proc.new { lowest_index( :include, C ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
268
|
+
::Proc.new { lowest_index( :include, A, B, C ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
269
|
+
::Proc.new { lowest_index( :extend, A, B ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
270
|
+
::Proc.new { lowest_index( :extend, E ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
###################
|
278
|
+
# highest_index #
|
279
|
+
###################
|
280
|
+
|
281
|
+
it 'can return the highest index for provided modules; throws exception if module provided is not found in stack' do
|
282
|
+
rspec = self
|
283
|
+
::Module::Cluster::InstanceController::HookController::HighestIndexMock = ::Module.new
|
284
|
+
::Module::Cluster::InstanceController::HookController::HighestIndexMock.module_eval do
|
285
|
+
|
286
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
287
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
288
|
+
|
289
|
+
module A
|
290
|
+
end
|
291
|
+
module B
|
292
|
+
end
|
293
|
+
module C
|
294
|
+
end
|
295
|
+
module D
|
296
|
+
end
|
297
|
+
module E
|
298
|
+
end
|
299
|
+
module F
|
300
|
+
end
|
301
|
+
|
302
|
+
hook_controller.include( A, B ).extend( C, D ).include( E ).extend( F ).instance_eval do
|
303
|
+
|
304
|
+
highest_index( :include, A, B ).should == 1
|
305
|
+
highest_index( :include, E, B ).should == 4
|
306
|
+
highest_index( :include, E ).should == 4
|
307
|
+
highest_index( :extend, C, D ).should == 3
|
308
|
+
highest_index( :extend, D ).should == 3
|
309
|
+
highest_index( :extend, F ).should == 5
|
310
|
+
|
311
|
+
::Proc.new { highest_index( :include, C ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
312
|
+
::Proc.new { highest_index( :include, A, B, C ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
313
|
+
::Proc.new { highest_index( :extend, A, B ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
314
|
+
::Proc.new { highest_index( :extend, E ) }.should rspec.raise_error( ::Module::Cluster::Exception::ModuleNotInStack )
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
##################################################################################################
|
322
|
+
# public #######################################################################################
|
323
|
+
##################################################################################################
|
324
|
+
|
325
|
+
############
|
326
|
+
# action #
|
327
|
+
############
|
328
|
+
|
329
|
+
it 'can create a block action to perform at hook' do
|
330
|
+
module ::Module::Cluster::InstanceController::HookController::ActionMock
|
331
|
+
|
332
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
333
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
334
|
+
|
335
|
+
block_ran = false
|
336
|
+
action_proc = ::Proc.new do
|
337
|
+
block_ran = true
|
338
|
+
end
|
339
|
+
hook_controller.action( & action_proc )
|
340
|
+
|
341
|
+
hook_controller.stack[ 0 ].module.should == nil
|
342
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
343
|
+
hook_controller.stack[ 0 ].action.should == nil
|
344
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
345
|
+
hook_controller.stack[ 0 ].block.should == action_proc
|
346
|
+
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
###########
|
351
|
+
# proxy #
|
352
|
+
###########
|
353
|
+
|
354
|
+
it 'can provide a proxy to return context-chained calls to self' do
|
355
|
+
module ::Module::Cluster::InstanceController::HookController::ProxyMock
|
356
|
+
|
357
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
358
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
359
|
+
|
360
|
+
chain_proxy = hook_controller.chain_proxy
|
361
|
+
chain_proxy.is_a?( ::Module::Cluster::InstanceController::HookController::ChainProxy ).should == true
|
362
|
+
chain_proxy.should == hook_controller.chain_proxy
|
363
|
+
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
####################
|
368
|
+
# before_include #
|
369
|
+
####################
|
370
|
+
|
371
|
+
it 'can chain methods specifying context for include/extend as before a given module include event' do
|
372
|
+
module ::Module::Cluster::InstanceController::HookController::BeforeIncludeMock
|
373
|
+
|
374
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
375
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
376
|
+
|
377
|
+
module A
|
378
|
+
end
|
379
|
+
module B
|
380
|
+
end
|
381
|
+
module C
|
382
|
+
end
|
383
|
+
module D
|
384
|
+
end
|
385
|
+
module E
|
386
|
+
end
|
387
|
+
module F
|
388
|
+
end
|
389
|
+
|
390
|
+
hook_controller.include( A, B ).extend( C, D )
|
391
|
+
|
392
|
+
hook_controller.before_include( B ).extend( F )
|
393
|
+
hook_controller.before_include( A ).include( E )
|
394
|
+
|
395
|
+
# E
|
396
|
+
|
397
|
+
hook_controller.stack[ 0 ].module.should == E
|
398
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
399
|
+
hook_controller.stack[ 0 ].action.should == :include
|
400
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
401
|
+
hook_controller.stack[ 0 ].block.should == nil
|
402
|
+
|
403
|
+
# A
|
404
|
+
|
405
|
+
hook_controller.stack[ 1 ].module.should == A
|
406
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
407
|
+
hook_controller.stack[ 1 ].action.should == :include
|
408
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
409
|
+
hook_controller.stack[ 1 ].block.should == nil
|
410
|
+
|
411
|
+
# F
|
412
|
+
|
413
|
+
hook_controller.stack[ 2 ].module.should == F
|
414
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
415
|
+
hook_controller.stack[ 2 ].action.should == :extend
|
416
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
417
|
+
hook_controller.stack[ 2 ].block.should == nil
|
418
|
+
|
419
|
+
# B
|
420
|
+
|
421
|
+
hook_controller.stack[ 3 ].module.should == B
|
422
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
423
|
+
hook_controller.stack[ 3 ].action.should == :include
|
424
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
425
|
+
hook_controller.stack[ 3 ].block.should == nil
|
426
|
+
|
427
|
+
# C
|
428
|
+
|
429
|
+
hook_controller.stack[ 4 ].module.should == C
|
430
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
431
|
+
hook_controller.stack[ 4 ].action.should == :extend
|
432
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
433
|
+
hook_controller.stack[ 4 ].block.should == nil
|
434
|
+
|
435
|
+
# D
|
436
|
+
|
437
|
+
hook_controller.stack[ 5 ].module.should == D
|
438
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
439
|
+
hook_controller.stack[ 5 ].action.should == :extend
|
440
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
441
|
+
hook_controller.stack[ 5 ].block.should == nil
|
442
|
+
|
443
|
+
end
|
444
|
+
end
|
445
|
+
|
446
|
+
###################
|
447
|
+
# before_extend #
|
448
|
+
###################
|
449
|
+
|
450
|
+
it 'can chain methods specifying context for include/extend as before a given module extend event' do
|
451
|
+
module ::Module::Cluster::InstanceController::HookController::BeforeExtendMock
|
452
|
+
|
453
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
454
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
455
|
+
|
456
|
+
module A
|
457
|
+
end
|
458
|
+
module B
|
459
|
+
end
|
460
|
+
module C
|
461
|
+
end
|
462
|
+
module D
|
463
|
+
end
|
464
|
+
module E
|
465
|
+
end
|
466
|
+
module F
|
467
|
+
end
|
468
|
+
|
469
|
+
hook_controller.include( A, B ).extend( C, D )
|
470
|
+
|
471
|
+
hook_controller.before_extend( C ).extend( F )
|
472
|
+
hook_controller.before_extend( D ).include( E )
|
473
|
+
|
474
|
+
# A
|
475
|
+
|
476
|
+
hook_controller.stack[ 0 ].module.should == A
|
477
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
478
|
+
hook_controller.stack[ 0 ].action.should == :include
|
479
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
480
|
+
hook_controller.stack[ 0 ].block.should == nil
|
481
|
+
|
482
|
+
# B
|
483
|
+
|
484
|
+
hook_controller.stack[ 1 ].module.should == B
|
485
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
486
|
+
hook_controller.stack[ 1 ].action.should == :include
|
487
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
488
|
+
hook_controller.stack[ 1 ].block.should == nil
|
489
|
+
|
490
|
+
# F
|
491
|
+
|
492
|
+
hook_controller.stack[ 2 ].module.should == F
|
493
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
494
|
+
hook_controller.stack[ 2 ].action.should == :extend
|
495
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
496
|
+
hook_controller.stack[ 2 ].block.should == nil
|
497
|
+
|
498
|
+
# C
|
499
|
+
|
500
|
+
hook_controller.stack[ 3 ].module.should == C
|
501
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
502
|
+
hook_controller.stack[ 3 ].action.should == :extend
|
503
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
504
|
+
hook_controller.stack[ 3 ].block.should == nil
|
505
|
+
|
506
|
+
# E
|
507
|
+
|
508
|
+
hook_controller.stack[ 4 ].module.should == E
|
509
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
510
|
+
hook_controller.stack[ 4 ].action.should == :include
|
511
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
512
|
+
hook_controller.stack[ 4 ].block.should == nil
|
513
|
+
|
514
|
+
# D
|
515
|
+
|
516
|
+
hook_controller.stack[ 5 ].module.should == D
|
517
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
518
|
+
hook_controller.stack[ 5 ].action.should == :extend
|
519
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
520
|
+
hook_controller.stack[ 5 ].block.should == nil
|
521
|
+
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
##############################
|
526
|
+
# before_include_or_extend #
|
527
|
+
##############################
|
528
|
+
|
529
|
+
it 'can chain methods specifying context for include/extend as before a given module include or extend event' do
|
530
|
+
module ::Module::Cluster::InstanceController::HookController::BeforeIncludeOrExtendMock
|
531
|
+
|
532
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
533
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
534
|
+
|
535
|
+
module A
|
536
|
+
end
|
537
|
+
module B
|
538
|
+
end
|
539
|
+
module C
|
540
|
+
end
|
541
|
+
module D
|
542
|
+
end
|
543
|
+
module E
|
544
|
+
end
|
545
|
+
module F
|
546
|
+
end
|
547
|
+
|
548
|
+
hook_controller.include( A, B ).extend( B, C ).include( C ).include_and_extend( D ).extend( A )
|
549
|
+
|
550
|
+
hook_controller.before_include_or_extend( B ).extend( F )
|
551
|
+
hook_controller.before_include_or_extend( A ).include_and_extend( E )
|
552
|
+
|
553
|
+
# E - include
|
554
|
+
|
555
|
+
hook_controller.stack[ 0 ].module.should == E
|
556
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
557
|
+
hook_controller.stack[ 0 ].action.should == :include
|
558
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
559
|
+
hook_controller.stack[ 0 ].block.should == nil
|
560
|
+
|
561
|
+
# E - extend
|
562
|
+
|
563
|
+
hook_controller.stack[ 1 ].module.should == E
|
564
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
565
|
+
hook_controller.stack[ 1 ].action.should == :extend
|
566
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
567
|
+
hook_controller.stack[ 1 ].block.should == nil
|
568
|
+
|
569
|
+
# A - include
|
570
|
+
|
571
|
+
hook_controller.stack[ 2 ].module.should == A
|
572
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
573
|
+
hook_controller.stack[ 2 ].action.should == :include
|
574
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
575
|
+
hook_controller.stack[ 2 ].block.should == nil
|
576
|
+
|
577
|
+
# F - extend
|
578
|
+
|
579
|
+
hook_controller.stack[ 3 ].module.should == F
|
580
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
581
|
+
hook_controller.stack[ 3 ].action.should == :extend
|
582
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
583
|
+
hook_controller.stack[ 3 ].block.should == nil
|
584
|
+
|
585
|
+
# B - include
|
586
|
+
|
587
|
+
hook_controller.stack[ 4 ].module.should == B
|
588
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
589
|
+
hook_controller.stack[ 4 ].action.should == :include
|
590
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
591
|
+
hook_controller.stack[ 4 ].block.should == nil
|
592
|
+
|
593
|
+
# B - extend
|
594
|
+
|
595
|
+
hook_controller.stack[ 5 ].module.should == B
|
596
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
597
|
+
hook_controller.stack[ 5 ].action.should == :extend
|
598
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
599
|
+
hook_controller.stack[ 5 ].block.should == nil
|
600
|
+
|
601
|
+
# C - extend
|
602
|
+
|
603
|
+
hook_controller.stack[ 6 ].module.should == C
|
604
|
+
hook_controller.stack[ 6 ].owner.should == instance_controller.instance
|
605
|
+
hook_controller.stack[ 6 ].action.should == :extend
|
606
|
+
hook_controller.stack[ 6 ].cascades.should == nil
|
607
|
+
hook_controller.stack[ 6 ].block.should == nil
|
608
|
+
|
609
|
+
# C - include
|
610
|
+
|
611
|
+
hook_controller.stack[ 7 ].module.should == C
|
612
|
+
hook_controller.stack[ 7 ].owner.should == instance_controller.instance
|
613
|
+
hook_controller.stack[ 7 ].action.should == :include
|
614
|
+
hook_controller.stack[ 7 ].cascades.should == nil
|
615
|
+
hook_controller.stack[ 7 ].block.should == nil
|
616
|
+
|
617
|
+
# D - include
|
618
|
+
|
619
|
+
hook_controller.stack[ 8 ].module.should == D
|
620
|
+
hook_controller.stack[ 8 ].owner.should == instance_controller.instance
|
621
|
+
hook_controller.stack[ 8 ].action.should == :include
|
622
|
+
hook_controller.stack[ 8 ].cascades.should == nil
|
623
|
+
hook_controller.stack[ 8 ].block.should == nil
|
624
|
+
|
625
|
+
# D - extend
|
626
|
+
|
627
|
+
hook_controller.stack[ 9 ].module.should == D
|
628
|
+
hook_controller.stack[ 9 ].owner.should == instance_controller.instance
|
629
|
+
hook_controller.stack[ 9 ].action.should == :extend
|
630
|
+
hook_controller.stack[ 9 ].cascades.should == nil
|
631
|
+
hook_controller.stack[ 9 ].block.should == nil
|
632
|
+
|
633
|
+
# A - extend
|
634
|
+
|
635
|
+
hook_controller.stack[ 10 ].module.should == A
|
636
|
+
hook_controller.stack[ 10 ].owner.should == instance_controller.instance
|
637
|
+
hook_controller.stack[ 10 ].action.should == :extend
|
638
|
+
hook_controller.stack[ 10 ].cascades.should == nil
|
639
|
+
hook_controller.stack[ 10 ].block.should == nil
|
640
|
+
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
644
|
+
###################
|
645
|
+
# after_include #
|
646
|
+
###################
|
647
|
+
|
648
|
+
it 'can chain methods specifying context for include/extend as after a given module include event' do
|
649
|
+
module ::Module::Cluster::InstanceController::HookController::AfterIncludeMock
|
650
|
+
|
651
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
652
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
653
|
+
|
654
|
+
module A
|
655
|
+
end
|
656
|
+
module B
|
657
|
+
end
|
658
|
+
module C
|
659
|
+
end
|
660
|
+
module D
|
661
|
+
end
|
662
|
+
module E
|
663
|
+
end
|
664
|
+
module F
|
665
|
+
end
|
666
|
+
|
667
|
+
hook_controller.include( A, B ).extend( C, D )
|
668
|
+
|
669
|
+
hook_controller.after_include( B ).extend( F )
|
670
|
+
hook_controller.after_include( A ).include( E )
|
671
|
+
|
672
|
+
# A
|
673
|
+
|
674
|
+
hook_controller.stack[ 0 ].module.should == A
|
675
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
676
|
+
hook_controller.stack[ 0 ].action.should == :include
|
677
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
678
|
+
hook_controller.stack[ 0 ].block.should == nil
|
679
|
+
|
680
|
+
# E
|
681
|
+
|
682
|
+
hook_controller.stack[ 1 ].module.should == E
|
683
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
684
|
+
hook_controller.stack[ 1 ].action.should == :include
|
685
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
686
|
+
hook_controller.stack[ 1 ].block.should == nil
|
687
|
+
|
688
|
+
# B
|
689
|
+
|
690
|
+
hook_controller.stack[ 2 ].module.should == B
|
691
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
692
|
+
hook_controller.stack[ 2 ].action.should == :include
|
693
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
694
|
+
hook_controller.stack[ 2 ].block.should == nil
|
695
|
+
|
696
|
+
# F
|
697
|
+
|
698
|
+
hook_controller.stack[ 3 ].module.should == F
|
699
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
700
|
+
hook_controller.stack[ 3 ].action.should == :extend
|
701
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
702
|
+
hook_controller.stack[ 3 ].block.should == nil
|
703
|
+
|
704
|
+
# C
|
705
|
+
|
706
|
+
hook_controller.stack[ 4 ].module.should == C
|
707
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
708
|
+
hook_controller.stack[ 4 ].action.should == :extend
|
709
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
710
|
+
hook_controller.stack[ 4 ].block.should == nil
|
711
|
+
|
712
|
+
# D
|
713
|
+
|
714
|
+
hook_controller.stack[ 5 ].module.should == D
|
715
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
716
|
+
hook_controller.stack[ 5 ].action.should == :extend
|
717
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
718
|
+
hook_controller.stack[ 5 ].block.should == nil
|
719
|
+
|
720
|
+
end
|
721
|
+
end
|
722
|
+
|
723
|
+
##################
|
724
|
+
# after_extend #
|
725
|
+
##################
|
726
|
+
|
727
|
+
it 'can chain methods specifying context for include/extend as after a given module extend event' do
|
728
|
+
module ::Module::Cluster::InstanceController::HookController::AfterExtendMock
|
729
|
+
|
730
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
731
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
732
|
+
|
733
|
+
module A
|
734
|
+
end
|
735
|
+
module B
|
736
|
+
end
|
737
|
+
module C
|
738
|
+
end
|
739
|
+
module D
|
740
|
+
end
|
741
|
+
module E
|
742
|
+
end
|
743
|
+
module F
|
744
|
+
end
|
745
|
+
|
746
|
+
hook_controller.include( A, B ).extend( C, D )
|
747
|
+
|
748
|
+
hook_controller.after_extend( C ).extend( F )
|
749
|
+
hook_controller.after_extend( D ).include( E )
|
750
|
+
|
751
|
+
# A
|
752
|
+
|
753
|
+
hook_controller.stack[ 0 ].module.should == A
|
754
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
755
|
+
hook_controller.stack[ 0 ].action.should == :include
|
756
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
757
|
+
hook_controller.stack[ 0 ].block.should == nil
|
758
|
+
|
759
|
+
# B
|
760
|
+
|
761
|
+
hook_controller.stack[ 1 ].module.should == B
|
762
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
763
|
+
hook_controller.stack[ 1 ].action.should == :include
|
764
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
765
|
+
hook_controller.stack[ 1 ].block.should == nil
|
766
|
+
|
767
|
+
# C
|
768
|
+
|
769
|
+
hook_controller.stack[ 2 ].module.should == C
|
770
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
771
|
+
hook_controller.stack[ 2 ].action.should == :extend
|
772
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
773
|
+
hook_controller.stack[ 2 ].block.should == nil
|
774
|
+
|
775
|
+
# F
|
776
|
+
|
777
|
+
hook_controller.stack[ 3 ].module.should == F
|
778
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
779
|
+
hook_controller.stack[ 3 ].action.should == :extend
|
780
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
781
|
+
hook_controller.stack[ 3 ].block.should == nil
|
782
|
+
|
783
|
+
# D
|
784
|
+
|
785
|
+
hook_controller.stack[ 4 ].module.should == D
|
786
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
787
|
+
hook_controller.stack[ 4 ].action.should == :extend
|
788
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
789
|
+
hook_controller.stack[ 4 ].block.should == nil
|
790
|
+
|
791
|
+
# E
|
792
|
+
|
793
|
+
hook_controller.stack[ 5 ].module.should == E
|
794
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
795
|
+
hook_controller.stack[ 5 ].action.should == :include
|
796
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
797
|
+
hook_controller.stack[ 5 ].block.should == nil
|
798
|
+
|
799
|
+
end
|
800
|
+
end
|
801
|
+
|
802
|
+
#############################
|
803
|
+
# after_include_or_extend #
|
804
|
+
#############################
|
805
|
+
|
806
|
+
it 'can chain methods specifying context for include/extend as after a given module include or extend event' do
|
807
|
+
module ::Module::Cluster::InstanceController::HookController::AfterIncludeOrExtendMock
|
808
|
+
|
809
|
+
instance_controller = ::Module::Cluster::InstanceController::HookController::Mock::InstanceController
|
810
|
+
hook_controller = ::Module::Cluster::InstanceController::HookController.new( :mock, instance_controller )
|
811
|
+
|
812
|
+
module A
|
813
|
+
end
|
814
|
+
module B
|
815
|
+
end
|
816
|
+
module C
|
817
|
+
end
|
818
|
+
module D
|
819
|
+
end
|
820
|
+
module E
|
821
|
+
end
|
822
|
+
module F
|
823
|
+
end
|
824
|
+
|
825
|
+
hook_controller.include( A, B ).extend( B, C ).include( C ).include_and_extend( D ).extend( A )
|
826
|
+
|
827
|
+
hook_controller.after_include_or_extend( B ).extend( F )
|
828
|
+
hook_controller.after_include_or_extend( A ).include_and_extend( E )
|
829
|
+
|
830
|
+
# A - include
|
831
|
+
|
832
|
+
hook_controller.stack[ 0 ].module.should == A
|
833
|
+
hook_controller.stack[ 0 ].owner.should == instance_controller.instance
|
834
|
+
hook_controller.stack[ 0 ].action.should == :include
|
835
|
+
hook_controller.stack[ 0 ].cascades.should == nil
|
836
|
+
hook_controller.stack[ 0 ].block.should == nil
|
837
|
+
|
838
|
+
# B - include
|
839
|
+
|
840
|
+
hook_controller.stack[ 1 ].module.should == B
|
841
|
+
hook_controller.stack[ 1 ].owner.should == instance_controller.instance
|
842
|
+
hook_controller.stack[ 1 ].action.should == :include
|
843
|
+
hook_controller.stack[ 1 ].cascades.should == nil
|
844
|
+
hook_controller.stack[ 1 ].block.should == nil
|
845
|
+
|
846
|
+
# B - extend
|
847
|
+
|
848
|
+
hook_controller.stack[ 2 ].module.should == B
|
849
|
+
hook_controller.stack[ 2 ].owner.should == instance_controller.instance
|
850
|
+
hook_controller.stack[ 2 ].action.should == :extend
|
851
|
+
hook_controller.stack[ 2 ].cascades.should == nil
|
852
|
+
hook_controller.stack[ 2 ].block.should == nil
|
853
|
+
|
854
|
+
# F - extend
|
855
|
+
|
856
|
+
hook_controller.stack[ 3 ].module.should == F
|
857
|
+
hook_controller.stack[ 3 ].owner.should == instance_controller.instance
|
858
|
+
hook_controller.stack[ 3 ].action.should == :extend
|
859
|
+
hook_controller.stack[ 3 ].cascades.should == nil
|
860
|
+
hook_controller.stack[ 3 ].block.should == nil
|
861
|
+
|
862
|
+
|
863
|
+
# C - extend
|
864
|
+
|
865
|
+
hook_controller.stack[ 4 ].module.should == C
|
866
|
+
hook_controller.stack[ 4 ].owner.should == instance_controller.instance
|
867
|
+
hook_controller.stack[ 4 ].action.should == :extend
|
868
|
+
hook_controller.stack[ 4 ].cascades.should == nil
|
869
|
+
hook_controller.stack[ 4 ].block.should == nil
|
870
|
+
|
871
|
+
# C - include
|
872
|
+
|
873
|
+
hook_controller.stack[ 5 ].module.should == C
|
874
|
+
hook_controller.stack[ 5 ].owner.should == instance_controller.instance
|
875
|
+
hook_controller.stack[ 5 ].action.should == :include
|
876
|
+
hook_controller.stack[ 5 ].cascades.should == nil
|
877
|
+
hook_controller.stack[ 5 ].block.should == nil
|
878
|
+
|
879
|
+
# D - include
|
880
|
+
|
881
|
+
hook_controller.stack[ 6 ].module.should == D
|
882
|
+
hook_controller.stack[ 6 ].owner.should == instance_controller.instance
|
883
|
+
hook_controller.stack[ 6 ].action.should == :include
|
884
|
+
hook_controller.stack[ 6 ].cascades.should == nil
|
885
|
+
hook_controller.stack[ 6 ].block.should == nil
|
886
|
+
|
887
|
+
# D - extend
|
888
|
+
|
889
|
+
hook_controller.stack[ 7 ].module.should == D
|
890
|
+
hook_controller.stack[ 7 ].owner.should == instance_controller.instance
|
891
|
+
hook_controller.stack[ 7 ].action.should == :extend
|
892
|
+
hook_controller.stack[ 7 ].cascades.should == nil
|
893
|
+
hook_controller.stack[ 7 ].block.should == nil
|
894
|
+
|
895
|
+
# A - extend
|
896
|
+
|
897
|
+
hook_controller.stack[ 8 ].module.should == A
|
898
|
+
hook_controller.stack[ 8 ].owner.should == instance_controller.instance
|
899
|
+
hook_controller.stack[ 8 ].action.should == :extend
|
900
|
+
hook_controller.stack[ 8 ].cascades.should == nil
|
901
|
+
hook_controller.stack[ 8 ].block.should == nil
|
902
|
+
|
903
|
+
# E - include
|
904
|
+
|
905
|
+
hook_controller.stack[ 9 ].module.should == E
|
906
|
+
hook_controller.stack[ 9 ].owner.should == instance_controller.instance
|
907
|
+
hook_controller.stack[ 9 ].action.should == :include
|
908
|
+
hook_controller.stack[ 9 ].cascades.should == nil
|
909
|
+
hook_controller.stack[ 9 ].block.should == nil
|
910
|
+
|
911
|
+
# E - extend
|
912
|
+
|
913
|
+
hook_controller.stack[ 10 ].module.should == E
|
914
|
+
hook_controller.stack[ 10 ].owner.should == instance_controller.instance
|
915
|
+
hook_controller.stack[ 10 ].action.should == :extend
|
916
|
+
hook_controller.stack[ 10 ].cascades.should == nil
|
917
|
+
hook_controller.stack[ 10 ].block.should == nil
|
918
|
+
|
919
|
+
end
|
920
|
+
end
|
921
|
+
|
922
|
+
end
|