module-cluster 1.4.8 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/README.md +127 -337
  2. data/lib/module-cluster.rb +1 -153
  3. data/lib/module/cluster.rb +341 -0
  4. data/lib/module/cluster/class_support.rb +22 -0
  5. data/lib/module/cluster/cluster.rb +10 -0
  6. data/lib/module/cluster/cluster/cluster_interface.rb +550 -0
  7. data/lib/module/cluster/exception/module_not_in_stack.rb +26 -0
  8. data/lib/module/cluster/instance_controller.rb +14 -0
  9. data/lib/module/cluster/instance_controller/hook_controller.rb +33 -0
  10. data/lib/module/cluster/instance_controller/hook_controller/chain_proxy.rb +511 -0
  11. data/lib/module/cluster/instance_controller/hook_controller/hook_controller_interface.rb +830 -0
  12. data/lib/module/cluster/instance_controller/instance_controller_interface.rb +269 -0
  13. data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy.rb +359 -0
  14. data/lib/module/cluster/instance_controller/multiple_hook_controller_proxy/chain_proxy.rb +442 -0
  15. data/lib/module/cluster/module_support.rb +67 -0
  16. data/lib/module/namespaces.rb +13 -0
  17. data/lib/module/requires.rb +32 -0
  18. data/spec/module/cluster/cluster_spec.rb +473 -0
  19. data/spec/module/cluster/instance_controller/hook_controller_spec.rb +922 -0
  20. data/spec/module/cluster/instance_controller/multiple_hook_controller_proxy_spec.rb +1240 -0
  21. data/spec/module/cluster_spec.rb +1794 -0
  22. metadata +27 -98
  23. data/README.rdoc +0 -395
  24. data/lib/module-cluster/ModuleCluster.rb +0 -9
  25. data/lib/module-cluster/ModuleCluster/Define.rb +0 -12
  26. data/lib/module-cluster/ModuleCluster/Define/Block.rb +0 -9
  27. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingClass.rb +0 -83
  28. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingClassOrModule.rb +0 -70
  29. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingModule.rb +0 -79
  30. data/lib/module-cluster/ModuleCluster/Define/Block/CascadingModuleOrSubclass.rb +0 -21
  31. data/lib/module-cluster/ModuleCluster/Define/Block/Class.rb +0 -77
  32. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb +0 -78
  33. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModule.rb +0 -78
  34. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrInstance.rb +0 -78
  35. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrSubclass.rb +0 -36
  36. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrSubclass.rb +0 -29
  37. data/lib/module-cluster/ModuleCluster/Define/Block/Instance.rb +0 -45
  38. data/lib/module-cluster/ModuleCluster/Define/Block/Module.rb +0 -77
  39. data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb +0 -78
  40. data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrSubclass.rb +0 -29
  41. data/lib/module-cluster/ModuleCluster/Define/Block/Subclass.rb +0 -56
  42. data/lib/module-cluster/ModuleCluster/Define/ClassCluster.rb +0 -193
  43. data/lib/module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb +0 -128
  44. data/lib/module-cluster/ModuleCluster/Define/Cluster.rb +0 -181
  45. data/lib/module-cluster/ModuleCluster/Define/ClusterCascades.rb +0 -185
  46. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb +0 -181
  47. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb +0 -181
  48. data/lib/module-cluster/ModuleCluster/Define/Deprecated.rb +0 -40
  49. data/lib/module-cluster/ModuleCluster/Define/InstanceCluster.rb +0 -45
  50. data/lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb +0 -193
  51. data/lib/module-cluster/ModuleCluster/Define/ModuleOrClassCluster.rb +0 -209
  52. data/lib/module-cluster/ModuleCluster/Define/ModuleOrInstanceCluster.rb +0 -128
  53. data/lib/module-cluster/ModuleCluster/Define/Status.rb +0 -106
  54. data/lib/module-cluster/ModuleCluster/Suspend.rb +0 -7
  55. data/lib/module-cluster/ModuleCluster/Suspend/Hooks.rb +0 -315
  56. data/lib/module-cluster/ModuleCluster/Suspend/WithoutHooks.rb +0 -153
  57. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures.rb +0 -77
  58. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb +0 -44
  59. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb +0 -292
  60. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclass.rb +0 -24
  61. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack.rb +0 -12
  62. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block.rb +0 -9
  63. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb +0 -36
  64. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Inherited.rb +0 -20
  65. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb +0 -20
  66. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb +0 -36
  67. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb +0 -6
  68. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb +0 -140
  69. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Includes.rb +0 -110
  70. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb +0 -140
  71. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb +0 -110
  72. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb +0 -35
  73. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy.rb +0 -359
  74. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Status.rb +0 -55
  75. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Suspend.rb +0 -199
  76. data/lib/module-cluster/_private_/ModuleCluster/ExtendForCascade.rb +0 -34
  77. data/spec/ModuleCluster/Define/Block/CascadingClassOrModule_spec.rb +0 -285
  78. data/spec/ModuleCluster/Define/Block/CascadingClass_spec.rb +0 -254
  79. data/spec/ModuleCluster/Define/Block/CascadingModuleOrSubclass_spec.rb +0 -56
  80. data/spec/ModuleCluster/Define/Block/CascadingModule_spec.rb +0 -278
  81. data/spec/ModuleCluster/Define/Block/ClassOrInstance_spec.rb +0 -230
  82. data/spec/ModuleCluster/Define/Block/ClassOrModuleOrInstance_spec.rb +0 -238
  83. data/spec/ModuleCluster/Define/Block/ClassOrModuleOrSubclass_spec.rb +0 -54
  84. data/spec/ModuleCluster/Define/Block/ClassOrModule_spec.rb +0 -231
  85. data/spec/ModuleCluster/Define/Block/ClassOrSubclass_spec.rb +0 -54
  86. data/spec/ModuleCluster/Define/Block/Class_spec.rb +0 -224
  87. data/spec/ModuleCluster/Define/Block/Instance_spec.rb +0 -78
  88. data/spec/ModuleCluster/Define/Block/ModuleOrInstance_spec.rb +0 -54
  89. data/spec/ModuleCluster/Define/Block/ModuleOrSubclass_spec.rb +0 -51
  90. data/spec/ModuleCluster/Define/Block/Module_spec.rb +0 -230
  91. data/spec/ModuleCluster/Define/Block/Subclass_spec.rb +0 -73
  92. data/spec/ModuleCluster/Define/Block_spec.rb +0 -18
  93. data/spec/ModuleCluster/Define/ClassCluster_spec.rb +0 -728
  94. data/spec/ModuleCluster/Define/ClassOrInstanceCluster_spec.rb +0 -576
  95. data/spec/ModuleCluster/Define/ClusterCascadesToClass_spec.rb +0 -659
  96. data/spec/ModuleCluster/Define/ClusterCascadesToModule_spec.rb +0 -678
  97. data/spec/ModuleCluster/Define/ClusterCascades_spec.rb +0 -644
  98. data/spec/ModuleCluster/Define/Cluster_spec.rb +0 -708
  99. data/spec/ModuleCluster/Define/InstanceCluster_spec.rb +0 -102
  100. data/spec/ModuleCluster/Define/ModuleCluster_spec.rb +0 -728
  101. data/spec/ModuleCluster/Define/ModuleOrClassCluster_spec.rb +0 -728
  102. data/spec/ModuleCluster/Define/ModuleOrInstanceCluster_spec.rb +0 -576
  103. data/spec/ModuleCluster/Suspend/Hooks_spec.rb +0 -573
  104. data/spec/ModuleCluster/Suspend/WithoutHooks_spec.rb +0 -559
  105. data/spec/ModuleCluster_spec.rb +0 -15
  106. data/spec/_private_/ModuleCluster/CascadeFeatures/PerformCascades_spec.rb +0 -386
  107. data/spec/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy_spec.rb +0 -419
  108. data/spec/_private_/ModuleCluster/ClusterStack/Suspend_spec.rb +0 -242
@@ -1,154 +1,2 @@
1
1
 
2
- module ::ModuleCluster
3
- class ClusterStack
4
- module Block
5
- module Class
6
- end
7
- module Instance
8
- end
9
- module Module
10
- end
11
- module Inherited
12
- end
13
- end
14
- module Status
15
- end
16
- module Suspend
17
- end
18
- end
19
- module CascadeFeatures
20
- module Subclass
21
- end
22
- module ClusterStack
23
- end
24
- module PerformCascades
25
- end
26
- end
27
- module ExtendForCascade
28
- module Subclass
29
- end
30
- end
31
- module Define
32
- module Block
33
- module Class
34
- end
35
- module ClassOrModule
36
- end
37
- module ClassOrInstance
38
- end
39
- module ClassOrSubclass
40
- end
41
- module ClassOrModuleOrSubclass
42
- end
43
- module Instance
44
- end
45
- module Module
46
- end
47
- module ModuleOrInstance
48
- end
49
- module ModuleOrSubclass
50
- end
51
- module CascadingClass
52
- end
53
- module CascadingClassOrModule
54
- end
55
- module CascadingModule
56
- end
57
- module CascadingModuleOrSubclass
58
- end
59
- end
60
- module ClusterStack
61
- end
62
- module Cluster
63
- end
64
- module ClassCluster
65
- end
66
- module ClassOrInstanceCluster
67
- end
68
- module ClusterCascades
69
- end
70
- module ClusterCascadesToClass
71
- end
72
- module ClusterCascadesToModule
73
- end
74
- module Deprecated
75
- end
76
- module InstanceCluster
77
- end
78
- module ::ModuleCluster
79
- end
80
- module ModuleOrClassCluster
81
- end
82
- module ModuleOrInstanceCluster
83
- end
84
- end
85
- module Suspend
86
- module Hooks
87
- end
88
- module WithoutHooks
89
- end
90
- end
91
- end
92
-
93
-
94
- require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb'
95
- require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb'
96
- require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclass.rb'
97
- require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures.rb'
98
-
99
- require_relative 'module-cluster/_private_/ModuleCluster/ExtendForCascade.rb'
100
-
101
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb'
102
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy.rb'
103
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Suspend.rb'
104
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Status.rb'
105
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Includes.rb'
106
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb'
107
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb'
108
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb'
109
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb'
110
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Inherited.rb'
111
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb'
112
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb'
113
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb'
114
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block.rb'
115
- require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack.rb'
116
-
117
- require_relative 'module-cluster/ModuleCluster/Suspend/Hooks.rb'
118
- require_relative 'module-cluster/ModuleCluster/Suspend/WithoutHooks.rb'
119
- require_relative 'module-cluster/ModuleCluster/Suspend.rb'
120
-
121
- require_relative 'module-cluster/ModuleCluster/Define/Cluster.rb'
122
- require_relative 'module-cluster/ModuleCluster/Define/ModuleCluster.rb'
123
- require_relative 'module-cluster/ModuleCluster/Define/ClassCluster.rb'
124
- require_relative 'module-cluster/ModuleCluster/Define/ModuleOrClassCluster.rb'
125
- require_relative 'module-cluster/ModuleCluster/Define/ModuleOrInstanceCluster.rb'
126
- require_relative 'module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb'
127
- require_relative 'module-cluster/ModuleCluster/Define/InstanceCluster.rb'
128
- require_relative 'module-cluster/ModuleCluster/Define/ClusterCascades.rb'
129
- require_relative 'module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb'
130
- require_relative 'module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb'
131
-
132
- require_relative 'module-cluster/ModuleCluster/Define/Block/Class.rb'
133
- require_relative 'module-cluster/ModuleCluster/Define/Block/Instance.rb'
134
- require_relative 'module-cluster/ModuleCluster/Define/Block/Module.rb'
135
- require_relative 'module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb'
136
- require_relative 'module-cluster/ModuleCluster/Define/Block/ClassOrModule.rb'
137
- require_relative 'module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb'
138
- require_relative 'module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrInstance.rb'
139
- require_relative 'module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrSubclass.rb'
140
- require_relative 'module-cluster/ModuleCluster/Define/Block/Subclass.rb'
141
- require_relative 'module-cluster/ModuleCluster/Define/Block/ModuleOrSubclass.rb'
142
- require_relative 'module-cluster/ModuleCluster/Define/Block/ClassOrSubclass.rb'
143
- require_relative 'module-cluster/ModuleCluster/Define/Block/CascadingClass.rb'
144
- require_relative 'module-cluster/ModuleCluster/Define/Block/CascadingModule.rb'
145
- require_relative 'module-cluster/ModuleCluster/Define/Block/CascadingClassOrModule.rb'
146
- require_relative 'module-cluster/ModuleCluster/Define/Block/CascadingModuleOrSubclass.rb'
147
- require_relative 'module-cluster/ModuleCluster/Define/Block.rb'
148
-
149
- require_relative 'module-cluster/ModuleCluster/Define/Deprecated.rb'
150
-
151
- require_relative 'module-cluster/ModuleCluster/Define.rb'
152
-
153
- require_relative 'module-cluster/ModuleCluster.rb'
154
-
2
+ require_relative 'module/cluster.rb'
@@ -0,0 +1,341 @@
1
+
2
+ # namespaces that have to be declared ahead of time for proper load order
3
+ require_relative './namespaces'
4
+
5
+ # source file requires
6
+ require_relative './requires.rb'
7
+
8
+ ###
9
+ # Public interface to enable modules/classes with module-cluster capabilities.
10
+ #
11
+ module ::Module::Cluster
12
+
13
+ @clusters = { }
14
+ @instances = { }
15
+
16
+ ###################
17
+ # self.extended #
18
+ ###################
19
+
20
+ ###
21
+ # Ensures that instance controller exists for extended instance
22
+ # and enables class or module support as appropriate.
23
+ #
24
+ def self.extended( instance )
25
+
26
+ case instance
27
+ when ::Class
28
+ instance.extend( ::Module::Cluster::ClassSupport )
29
+ when ::Module
30
+ instance.extend( ::Module::Cluster::ModuleSupport )
31
+ end
32
+
33
+ end
34
+
35
+ #############
36
+ # cluster #
37
+ #############
38
+
39
+ ###
40
+ # Get cluster for name. Will create cluster if it does not already exist.
41
+ #
42
+ # @param name Name of cluster.
43
+ #
44
+ def cluster( name )
45
+
46
+ return ::Module::Cluster.cluster( self, name )
47
+
48
+ end
49
+
50
+ ##################################################################################################
51
+ # private ######################################################################################
52
+ ##################################################################################################
53
+
54
+ ###
55
+ # These methods are not actually in private space but are internal methods for inter-object
56
+ # communications. They aren't intended for public interfacing.
57
+ #
58
+
59
+ ##################
60
+ # self.cluster #
61
+ ##################
62
+
63
+ ###
64
+ # @private
65
+ #
66
+ # Return cluster for instance or create if necessary
67
+ #
68
+ # @param instance
69
+ # Instance for which cluster is being created.
70
+ #
71
+ # @param name
72
+ # Name of cluster for instance.
73
+ #
74
+ # @return [ModuleCluster::Cluster::Cluster] Cluster instance.
75
+ #
76
+ def self.cluster( instance, name )
77
+
78
+ unless instance_hash = @clusters[ instance ]
79
+ @clusters[ instance ] = instance_hash = { }
80
+ end
81
+
82
+ unless cluster_instance = instance_hash[ name ]
83
+ instance_hash[ name ] = cluster_instance = ::Module::Cluster::Cluster.new( instance, name )
84
+ end
85
+
86
+ return cluster_instance
87
+
88
+ end
89
+
90
+ ##############################
91
+ # self.instance_controller #
92
+ ##############################
93
+
94
+ ###
95
+ # @private
96
+ #
97
+ # Return instance controller for instance or create if necessary
98
+ #
99
+ # @param instance
100
+ # Instance for which instance controller is being created.
101
+ #
102
+ # @return [ModuleCluster::Cluster::InstanceController] Instance Controller instance.
103
+ #
104
+ def self.instance_controller( instance )
105
+
106
+ unless instance_controller = @instances[ instance ]
107
+ @instances[ instance ] = instance_controller = self::InstanceController.new( instance )
108
+ end
109
+
110
+ return instance_controller
111
+
112
+ end
113
+
114
+ ######################################
115
+ # self.hook_controller_for_context #
116
+ ######################################
117
+
118
+ ###
119
+ # @private
120
+ #
121
+ # Return instance controller for instance or create if necessary
122
+ #
123
+ # @param instance
124
+ # Instance for which Hook Controller is being returned.
125
+ #
126
+ # @param event_context
127
+ # Context for which event hooks are being processed.
128
+ #
129
+ # @return [ModuleCluster::Cluster::InstanceController::HookController] Hook Controller instance.
130
+ #
131
+ def self.hook_controller_for_context( instance, event_context )
132
+
133
+ hook_stack = nil
134
+
135
+ instance_controller = instance_controller( instance )
136
+
137
+ case event_context
138
+
139
+ when :before_include
140
+
141
+ hook_stack = instance_controller.before_include_controller
142
+
143
+ when :after_include
144
+
145
+ hook_stack = instance_controller.after_include_controller
146
+
147
+ when :before_extend
148
+
149
+ hook_stack = instance_controller.before_extend_controller
150
+
151
+ when :after_extend
152
+
153
+ hook_stack = instance_controller.after_extend_controller
154
+
155
+ when :subclass
156
+
157
+ hook_stack = instance_controller.subclass_controller
158
+
159
+ end
160
+
161
+ return hook_stack
162
+
163
+ end
164
+
165
+ ##############################
166
+ # self.hook_cluster_events #
167
+ ##############################
168
+
169
+ ###
170
+ # @private
171
+ #
172
+ # Return instance controller for instance or create if necessary
173
+ #
174
+ # @param instance
175
+ # Module cluster enabled instance for which hooks are being activated.
176
+ #
177
+ # @param hooked_instance
178
+ # Iheriting instance for which events are being processed.
179
+ #
180
+ # @param event_context
181
+ # Context for which event hooks are being processed.
182
+ #
183
+ # @return [ModuleCluster::Cluster::InstanceController::HookController] Hook Controller instance.
184
+ #
185
+ def self.hook_cluster_events( instance, hooked_instance, event_context )
186
+
187
+ requires_module_cluster_enable = false
188
+
189
+ # Subclass hooks always cascade to the first subclass.
190
+ # If it should casade for each subclass that has to be declared explicitly and will be handled below.
191
+ unless event_context == :subclass
192
+ instance_controller = instance_controller( instance )
193
+ if instance_controller.instance_variable_defined?( :@subclass_controller )
194
+ hooked_instance_controller = instance_controller( hooked_instance )
195
+ hooked_instance_controller.subclass_controller.stack.concat( instance_controller.subclass_controller.stack )
196
+ requires_module_cluster_enable = true
197
+ end
198
+ end
199
+
200
+ hook_controller_for_context( instance, event_context ).stack.each do |this_frame|
201
+
202
+ cascade_controller = event_context
203
+
204
+ # test to see if this frame's cluster is disabled
205
+ unless cluster( instance, this_frame.cluster ).disabled?
206
+
207
+ should_cascade = false
208
+ should_perform_action = nil
209
+
210
+ # if we cascade we do that first - test to see if we should cascade into instance
211
+ if cascade_context = this_frame.cascades
212
+
213
+ if cascade_context.include?( :any )
214
+
215
+ should_cascade = true
216
+ should_perform_action = true
217
+
218
+ case hooked_instance
219
+ when ::Class
220
+ cascade_controller = :subclass
221
+ end
222
+
223
+ else
224
+
225
+ case hooked_instance
226
+ when ::Class
227
+ if event_context == :subclass
228
+ if cascade_context.include?( :subclass )
229
+ should_cascade = true
230
+ should_perform_action = true
231
+ end
232
+ else
233
+ has_subclass = cascade_context.include?( :subclass )
234
+ has_class = cascade_context.include?( :class )
235
+ if has_class and has_subclass
236
+ should_cascade = true
237
+ should_perform_action = true
238
+ cascade_controller = :subclass
239
+ elsif has_class
240
+ should_cascade = true
241
+ should_perform_action = true
242
+ elsif has_subclass
243
+ should_cascade = true
244
+ should_perform_action = false
245
+ cascade_controller = :subclass
246
+ end
247
+ end
248
+ when ::Module
249
+ if cascade_context.include?( :module )
250
+ should_cascade = true
251
+ should_perform_action = true
252
+ elsif cascade_context.include?( :class ) or cascade_context.include?( :subclass )
253
+ should_cascade = true
254
+ should_perform_action = false
255
+ end
256
+ end
257
+
258
+ end
259
+
260
+ if should_cascade
261
+ requires_module_cluster_enable = true
262
+ hook_controller_for_context( hooked_instance, cascade_controller ).stack.push( this_frame )
263
+ end
264
+
265
+ end
266
+
267
+ if cascade_context
268
+
269
+ # already handled
270
+
271
+ elsif match_context = this_frame.context
272
+
273
+ # if we have a context we test against instance to see if we match, then we perform action
274
+ case hooked_instance
275
+ when ::Class
276
+ if event_context == :subclass
277
+ if match_context.include?( :subclass )
278
+ should_perform_action = true
279
+ end
280
+ else
281
+ if match_context.include?( :class )
282
+ should_perform_action = true
283
+ end
284
+ end
285
+ when ::Module
286
+ if match_context.include?( :module )
287
+ should_perform_action = true
288
+ end
289
+ else
290
+ if match_context.include?( :instance )
291
+ should_perform_action = true
292
+ end
293
+ end
294
+
295
+ else
296
+
297
+ # if we are supposed to cascade (and have no context) then we perform action
298
+ # if we don't have a context then we perform action
299
+ should_perform_action = true
300
+
301
+ end
302
+
303
+ if should_perform_action
304
+
305
+ # if we have a module to include/extend
306
+ if this_module = this_frame.module
307
+ case this_action = this_frame.action
308
+ when :include
309
+ hooked_instance.module_eval do
310
+ include this_module
311
+ end
312
+ when :extend
313
+ hooked_instance.extend( this_module )
314
+ end
315
+ end
316
+
317
+ # if we have a block it runs last
318
+ if this_block = this_frame.block
319
+ this_block.call( hooked_instance )
320
+ end
321
+
322
+ end
323
+
324
+ end
325
+
326
+ end
327
+
328
+ if requires_module_cluster_enable
329
+
330
+ case hooked_instance
331
+ when ::Class
332
+ hooked_instance.extend( ::Module::Cluster::ClassSupport )
333
+ when ::Module
334
+ hooked_instance.extend( ::Module::Cluster::ModuleSupport )
335
+ end
336
+
337
+ end
338
+
339
+ end
340
+
341
+ end