module-cluster 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/module/cluster.rb +4 -4
- data/lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb +12 -12
- data/lib/module/cluster/instance_controller/hook_controller/hook_controller_interface.rb +1 -1
- data/lib/module/cluster/module_support.rb +1 -1
- data/spec/module/cluster_spec.rb +124 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Provides an interface for event hooks at any point during module include/extend
|
|
8
8
|
|
9
9
|
# Description #
|
10
10
|
|
11
|
-
Provides hooks via :included, :extended, :append_features, :extend_object, :
|
11
|
+
Provides hooks via :included, :extended, :append_features, :extend_object, :inherited. Define behavior at hooks via simple interface.
|
12
12
|
|
13
13
|
# Install #
|
14
14
|
|
data/lib/module/cluster.rb
CHANGED
@@ -183,7 +183,7 @@ module ::Module::Cluster
|
|
183
183
|
# @return [ModuleCluster::Cluster::InstanceController::HookController] Hook Controller instance.
|
184
184
|
#
|
185
185
|
def self.hook_cluster_events( instance, hooked_instance, event_context )
|
186
|
-
|
186
|
+
|
187
187
|
requires_module_cluster_enable = false
|
188
188
|
|
189
189
|
# Subclass hooks always cascade to the first subclass.
|
@@ -264,11 +264,11 @@ module ::Module::Cluster
|
|
264
264
|
|
265
265
|
end
|
266
266
|
|
267
|
-
if cascade_context
|
268
|
-
|
267
|
+
if cascade_context and ! cascade_context.empty?
|
268
|
+
|
269
269
|
# already handled
|
270
270
|
|
271
|
-
elsif match_context = this_frame.context
|
271
|
+
elsif match_context = this_frame.context and ! match_context.empty?
|
272
272
|
|
273
273
|
# if we have a context we test against instance to see if we match, then we perform action
|
274
274
|
case hooked_instance
|
@@ -32,7 +32,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
32
32
|
###
|
33
33
|
# Declare that modules should be included at event hook in the context specified this chained declaration.
|
34
34
|
#
|
35
|
-
# @overload include( module,
|
35
|
+
# @overload include( module, ..., & block )
|
36
36
|
#
|
37
37
|
# @param module Module to include at event hook in the context specified this chained declaration.
|
38
38
|
#
|
@@ -57,7 +57,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
57
57
|
###
|
58
58
|
# Declare that modules should be extended at event hook in the context specified this chained declaration.
|
59
59
|
#
|
60
|
-
# @overload extend( module,
|
60
|
+
# @overload extend( module, ..., & block )
|
61
61
|
#
|
62
62
|
# @param module Module to extend at event hook in the context specified this chained declaration.
|
63
63
|
#
|
@@ -89,7 +89,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
89
89
|
# Declare that modules should be included and extended at event hook in the context
|
90
90
|
# specified this chained declaration. See also #extend_and_include.
|
91
91
|
#
|
92
|
-
# @overload include_and_extend( module,
|
92
|
+
# @overload include_and_extend( module, ..., & block )
|
93
93
|
#
|
94
94
|
# @param module Module to include and extend at event hook in the context specified this chained declaration.
|
95
95
|
#
|
@@ -121,7 +121,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
121
121
|
# Declare that modules should be extended and included at event hook in the context
|
122
122
|
# specified this chained declaration. Order is reversed from #include_and_extend.
|
123
123
|
#
|
124
|
-
# @overload extend_and_include( module,
|
124
|
+
# @overload extend_and_include( module, ..., & block )
|
125
125
|
#
|
126
126
|
# @param module Module to extend and include at event hook in the context specified this chained declaration.
|
127
127
|
#
|
@@ -175,7 +175,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
175
175
|
###
|
176
176
|
# Declare contexts to which declarations made from this declaration chain should cascade.
|
177
177
|
#
|
178
|
-
# @overload cascade( context,
|
178
|
+
# @overload cascade( context, ..., & block )
|
179
179
|
#
|
180
180
|
# @param context nil, :any, :class, :module, :subclass Contexts that should have event hooks cascaded into them.
|
181
181
|
#
|
@@ -226,7 +226,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
226
226
|
# Declare that chained actions should be inserted into the event stack prior to the location
|
227
227
|
# in the same event stack where provided module(s) are specified to be extended.
|
228
228
|
#
|
229
|
-
# @overload before_extend( module,
|
229
|
+
# @overload before_extend( module, ..., & block )
|
230
230
|
#
|
231
231
|
# @param module Module that insert should be prior to.
|
232
232
|
#
|
@@ -252,7 +252,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
252
252
|
# Declare that chained actions should be inserted into the event stack prior to the location
|
253
253
|
# in the same event stack where provided module(s) are specified to be included.
|
254
254
|
#
|
255
|
-
# @overload before_include( module,
|
255
|
+
# @overload before_include( module, ..., & block )
|
256
256
|
#
|
257
257
|
# @param module Module that insert should be prior to.
|
258
258
|
#
|
@@ -279,7 +279,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
279
279
|
# Declare that chained actions should be inserted into the event stack prior to the location
|
280
280
|
# in the same event stack where provided module(s) are specified to be included or extended.
|
281
281
|
#
|
282
|
-
# @overload before_include_or_extend( module,
|
282
|
+
# @overload before_include_or_extend( module, ..., & block )
|
283
283
|
#
|
284
284
|
# @param module Module that insert should be prior to.
|
285
285
|
#
|
@@ -307,7 +307,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
307
307
|
# Declare that chained actions should be inserted into the event stack after the location
|
308
308
|
# in the same event stack where provided module(s) are specified to be included.
|
309
309
|
#
|
310
|
-
# @overload before_include( module,
|
310
|
+
# @overload before_include( module, ..., & block )
|
311
311
|
#
|
312
312
|
# @param module Module that insert should be after.
|
313
313
|
#
|
@@ -333,7 +333,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
333
333
|
# Declare that chained actions should be inserted into the event stack after the location
|
334
334
|
# in the same event stack where provided module(s) are specified to be extended.
|
335
335
|
#
|
336
|
-
# @overload before_extend( module,
|
336
|
+
# @overload before_extend( module, ..., & block )
|
337
337
|
#
|
338
338
|
# @param module Module that insert should be after.
|
339
339
|
#
|
@@ -360,7 +360,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
360
360
|
# Declare that chained actions should be inserted into the event stack after the location
|
361
361
|
# in the same event stack where provided module(s) are specified to be included or extended.
|
362
362
|
#
|
363
|
-
# @overload before_include_or_extend( module,
|
363
|
+
# @overload before_include_or_extend( module, ..., & block )
|
364
364
|
#
|
365
365
|
# @param module Module that insert should be after.
|
366
366
|
#
|
@@ -387,7 +387,7 @@ class ::Module::Cluster::InstanceController::HookController::ChainProxy
|
|
387
387
|
###
|
388
388
|
# Set context for matching instance to determine whether to perform chained actions in stack.
|
389
389
|
#
|
390
|
-
# @overload context( context,
|
390
|
+
# @overload context( context, ... )
|
391
391
|
#
|
392
392
|
# @param context nil, :any, :class, :module, :subclass Contexts that should have event hooks cascaded into them.
|
393
393
|
#
|
@@ -670,7 +670,7 @@ module ::Module::Cluster::InstanceController::HookController::HookControllerInte
|
|
670
670
|
new_frame = self.class::FrameStruct.new( @instance, cluster_name, contexts, cascade_to, block )
|
671
671
|
|
672
672
|
@stack.insert( index, new_frame )
|
673
|
-
|
673
|
+
|
674
674
|
unless index < 0
|
675
675
|
index += 1
|
676
676
|
end
|
@@ -12,7 +12,7 @@ module ::Module::Cluster::ModuleSupport
|
|
12
12
|
# Ensures {::Module::Cluster Module::Cluster} before_include hooks occur at time of include.
|
13
13
|
#
|
14
14
|
def append_features( hooked_instance )
|
15
|
-
|
15
|
+
|
16
16
|
::Module::Cluster.hook_cluster_events( self, hooked_instance, :before_include )
|
17
17
|
|
18
18
|
super if defined?( super )
|
data/spec/module/cluster_spec.rb
CHANGED
@@ -27,6 +27,68 @@ describe ::Module::Cluster do
|
|
27
27
|
# include hooks #
|
28
28
|
###################
|
29
29
|
|
30
|
+
# before - block only
|
31
|
+
it 'can create a before-include hook to run a block' do
|
32
|
+
module ::Module::Cluster::BeforeIncludeBlockHookMock
|
33
|
+
|
34
|
+
block_ran = false
|
35
|
+
|
36
|
+
ClusterModuleMock = ::Module.new
|
37
|
+
ClusterModuleMock.instance_eval do
|
38
|
+
extend ::Module::Cluster
|
39
|
+
cluster( :cluster_name ).before_include do |instance|
|
40
|
+
block_ran = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module AnotherModule
|
45
|
+
include ClusterModuleMock
|
46
|
+
end
|
47
|
+
|
48
|
+
block_ran.should == true
|
49
|
+
|
50
|
+
block_ran = false
|
51
|
+
|
52
|
+
module OtherModule
|
53
|
+
include AnotherModule
|
54
|
+
end
|
55
|
+
|
56
|
+
block_ran.should == false
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# after - block only
|
62
|
+
it 'can create an after-include hook to run a block' do
|
63
|
+
module ::Module::Cluster::BeforeIncludeBlockHookMock
|
64
|
+
|
65
|
+
block_ran = false
|
66
|
+
|
67
|
+
ClusterModuleMock = ::Module.new
|
68
|
+
ClusterModuleMock.instance_eval do
|
69
|
+
extend ::Module::Cluster
|
70
|
+
cluster( :cluster_name ).after_include do |instance|
|
71
|
+
block_ran = true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module AnotherModule
|
76
|
+
include ClusterModuleMock
|
77
|
+
end
|
78
|
+
|
79
|
+
block_ran.should == true
|
80
|
+
|
81
|
+
block_ran = false
|
82
|
+
|
83
|
+
module OtherModule
|
84
|
+
include AnotherModule
|
85
|
+
end
|
86
|
+
|
87
|
+
block_ran.should == false
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
30
92
|
# before - without block
|
31
93
|
|
32
94
|
it 'can create before-include hooks' do
|
@@ -179,6 +241,68 @@ describe ::Module::Cluster do
|
|
179
241
|
# extend hooks #
|
180
242
|
##################
|
181
243
|
|
244
|
+
# before - block only
|
245
|
+
it 'can create a before-extend hook to run a block' do
|
246
|
+
module ::Module::Cluster::BeforeIncludeBlockHookMock
|
247
|
+
|
248
|
+
block_ran = false
|
249
|
+
|
250
|
+
ClusterModuleMock = ::Module.new
|
251
|
+
ClusterModuleMock.instance_eval do
|
252
|
+
extend ::Module::Cluster
|
253
|
+
cluster( :cluster_name ).before_extend do |instance|
|
254
|
+
block_ran = true
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
module AnotherModule
|
259
|
+
extend ClusterModuleMock
|
260
|
+
end
|
261
|
+
|
262
|
+
block_ran.should == true
|
263
|
+
|
264
|
+
block_ran = false
|
265
|
+
|
266
|
+
module OtherModule
|
267
|
+
extend AnotherModule
|
268
|
+
end
|
269
|
+
|
270
|
+
block_ran.should == false
|
271
|
+
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# after - block only
|
276
|
+
it 'can create a after-extend hook to run a block' do
|
277
|
+
module ::Module::Cluster::BeforeIncludeBlockHookMock
|
278
|
+
|
279
|
+
block_ran = false
|
280
|
+
|
281
|
+
ClusterModuleMock = ::Module.new
|
282
|
+
ClusterModuleMock.instance_eval do
|
283
|
+
extend ::Module::Cluster
|
284
|
+
cluster( :cluster_name ).after_extend do |instance|
|
285
|
+
block_ran = true
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
module AnotherModule
|
290
|
+
extend ClusterModuleMock
|
291
|
+
end
|
292
|
+
|
293
|
+
block_ran.should == true
|
294
|
+
|
295
|
+
block_ran = false
|
296
|
+
|
297
|
+
module OtherModule
|
298
|
+
extend AnotherModule
|
299
|
+
end
|
300
|
+
|
301
|
+
block_ran.should == false
|
302
|
+
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
182
306
|
# before - without block
|
183
307
|
|
184
308
|
it 'can create before-extend hooks' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: module-cluster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides hooks via :included, :extended, :append_features, :extend_object,
|
15
|
-
:
|
15
|
+
:inherited. Define behavior at hooks via simple interface.
|
16
16
|
email: asher@ridiculouspower.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|