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,110 +0,0 @@
1
-
2
- module ::ModuleCluster::ClusterStack::PrependsIncludes
3
-
4
- ##############################
5
- # prepend_include_hooks #
6
- ##############################
7
-
8
- def prepend_include_hooks
9
- return @prepend_include_hooks ||= ::ModuleCluster::ClusterStack::Set::MultiSetProxy.new
10
- end
11
-
12
- ###############################
13
- # include_prepends_includes #
14
- ###############################
15
-
16
- def include_prepends_includes( module_instance, method, includes, runtime_includes_block )
17
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :all, :include, includes, runtime_includes_block )
18
- prepend_include_hooks.push( new_set )
19
- return new_set
20
- end
21
-
22
- ##############################
23
- # include_prepends_extends #
24
- ##############################
25
-
26
- def include_prepends_extends( module_instance, method, extends, runtime_extends_block )
27
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :all, :extend, extends, runtime_extends_block )
28
- prepend_include_hooks.push( new_set )
29
- return new_set
30
- end
31
-
32
- ###########################################
33
- # include_prepends_includes_and_extends #
34
- ###########################################
35
-
36
- def include_prepends_includes_and_extends( module_instance, method, includes_and_extends, runtime_includes_and_extends_block )
37
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :all, :include_and_extend, includes_and_extends, runtime_includes_and_extends_block )
38
- prepend_include_hooks.push( new_set )
39
- return new_set
40
- end
41
-
42
- ######################################
43
- # module_include_prepends_includes #
44
- ######################################
45
-
46
- def module_include_prepends_includes( module_instance, method, includes, runtime_includes_block )
47
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :module, :include, includes, runtime_includes_block )
48
- prepend_include_hooks.push( new_set )
49
- return new_set
50
- end
51
-
52
- #####################################
53
- # module_include_prepends_extends #
54
- #####################################
55
-
56
- def module_include_prepends_extends( module_instance, method, extends, runtime_extends_block )
57
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :module, :extend, extends, runtime_extends_block )
58
- prepend_include_hooks.push( new_set )
59
- return new_set
60
- end
61
-
62
- ##################################################
63
- # module_include_prepends_includes_and_extends #
64
- ##################################################
65
-
66
- def module_include_prepends_includes_and_extends( module_instance, method, includes_and_extends, runtime_includes_and_extends_block )
67
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :module, :include_and_extend, includes_and_extends, runtime_includes_and_extends_block )
68
- prepend_include_hooks.push( new_set )
69
- return new_set
70
- end
71
-
72
- #####################################
73
- # class_include_prepends_includes #
74
- #####################################
75
-
76
- def class_include_prepends_includes( module_instance, method, includes, runtime_includes_block )
77
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :class, :include, includes, runtime_includes_block )
78
- prepend_include_hooks.push( new_set )
79
- return new_set
80
- end
81
-
82
- ####################################
83
- # class_include_prepends_extends #
84
- ####################################
85
-
86
- def class_include_prepends_extends( module_instance, method, extends, runtime_extends_block )
87
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :class, :extend, extends, runtime_extends_block )
88
- prepend_include_hooks.push( new_set )
89
- return new_set
90
- end
91
-
92
- #################################################
93
- # class_include_prepends_includes_and_extends #
94
- #################################################
95
-
96
- def class_include_prepends_includes_and_extends( module_instance, method, includes_and_extends, runtime_includes_and_extends_block )
97
- new_set = ::ModuleCluster::ClusterStack::Set.new( module_instance, method, :class, :include_and_extend, includes_and_extends, runtime_includes_and_extends_block )
98
- prepend_include_hooks.push( new_set )
99
- return new_set
100
- end
101
-
102
- ###############################
103
- # has_prepend_include_hook? #
104
- ###############################
105
-
106
- def has_prepend_include_hook?( description )
107
- return prepend_include_hooks.hooks_with( description ) || false
108
- end
109
-
110
- end
@@ -1,35 +0,0 @@
1
-
2
- ModuleCluster::ClusterStack::Set = Struct.new( :dependency_module,
3
- :method,
4
- :module_class_instance_or_all,
5
- :include_or_extend,
6
- :modules,
7
- :runtime_includes_or_extends_block,
8
- :suspended,
9
- :name ) do
10
-
11
- #############
12
- # suspend #
13
- #############
14
-
15
- def suspend
16
- suspended = true
17
- end
18
-
19
- ############
20
- # resume #
21
- ############
22
-
23
- def resume
24
- suspended = false
25
- end
26
-
27
- ################
28
- # suspended? #
29
- ################
30
-
31
- def suspended?
32
- return suspended
33
- end
34
-
35
- end
@@ -1,359 +0,0 @@
1
-
2
- class ::ModuleCluster::ClusterStack::Set::MultiSetProxy < Array
3
-
4
- ################
5
- # initialize #
6
- ################
7
-
8
- def initialize( *members )
9
- super( members )
10
- end
11
-
12
- ##########
13
- # name #
14
- ##########
15
-
16
- def name
17
- return collect { |this_set| this_set.name }.flatten
18
- end
19
-
20
- ###########
21
- # name= #
22
- ###########
23
-
24
- def name=( set_name )
25
-
26
- self.each do |this_set|
27
- this_set.name = set_name
28
- end
29
-
30
- return set_name
31
-
32
- end
33
-
34
- #######################
35
- # dependency_module #
36
- #######################
37
-
38
- def dependency_module
39
- return collect { |this_set| this_set.dependency_module }.flatten
40
- end
41
-
42
- ########################
43
- # dependency_module= #
44
- ########################
45
-
46
- def dependency_module=( set_dependency_module )
47
-
48
- self.each do |this_set|
49
- this_set.dependency_module = set_dependency_module
50
- end
51
-
52
- return set_dependency_module
53
-
54
- end
55
-
56
- ############
57
- # method #
58
- ############
59
-
60
- def method
61
- return collect { |this_set| this_set.method }.flatten
62
- end
63
-
64
- #############
65
- # method= #
66
- #############
67
-
68
- def method=( set_method )
69
-
70
- self.each do |this_set|
71
- this_set.method = set_method
72
- end
73
-
74
- return set_method
75
-
76
- end
77
-
78
- ##################################
79
- # module_class_instance_or_all #
80
- ##################################
81
-
82
- def module_class_instance_or_all
83
- return collect { |this_set| this_set.module_class_instance_or_all }.flatten
84
- end
85
-
86
- ###################################
87
- # module_class_instance_or_all= #
88
- ###################################
89
-
90
- def module_class_instance_or_all=( symbol_module_class_instance_or_all )
91
-
92
- self.each do |this_set|
93
- this_set.module_class_instance_or_all = symbol_module_class_instance_or_all
94
- end
95
-
96
- return symbol_module_class_instance_or_all
97
-
98
- end
99
-
100
- #######################
101
- # include_or_extend #
102
- #######################
103
-
104
- def include_or_extend
105
- return collect { |this_set| this_set.method }.flatten
106
- end
107
-
108
- ########################
109
- # include_or_extend= #
110
- ########################
111
-
112
- def include_or_extend=( symbol_include_or_extend )
113
-
114
- self.each do |this_set|
115
- this_set.method = symbol_include_or_extend
116
- end
117
-
118
- return symbol_include_or_extend
119
-
120
- end
121
-
122
- #############
123
- # modules #
124
- #############
125
-
126
- def modules
127
- modules = Array.new
128
- self.each do |this_set|
129
- if this_set.is_a?( ::ModuleCluster::ClusterStack::Set::MultiSetProxy )
130
- modules.concat( this_set.modules )
131
- else
132
- modules.push( this_set.modules )
133
- end
134
- end
135
- return modules
136
- end
137
-
138
- ##############
139
- # modules= #
140
- ##############
141
-
142
- def modules=( array_of_modules )
143
-
144
- self.each do |this_set|
145
- this_set.modules = array_of_modules
146
- end
147
-
148
- return array_of_modules
149
-
150
- end
151
-
152
- #######################################
153
- # runtime_includes_or_extends_block #
154
- #######################################
155
-
156
- def runtime_includes_or_extends_block
157
- return collect { |this_set| this_set.runtime_includes_or_extends_block }.flatten
158
- end
159
-
160
- ########################################
161
- # runtime_includes_or_extends_block= #
162
- ########################################
163
-
164
- def runtime_includes_or_extends_block=( runtime_includes_or_extends_proc )
165
-
166
- self.each do |this_set|
167
- this_set.runtime_includes_or_extends_block = runtime_includes_or_extends_proc
168
- end
169
-
170
- return runtime_includes_or_extends_proc
171
-
172
- end
173
-
174
- ###############
175
- # suspended #
176
- ###############
177
-
178
- def suspended
179
- return collect do |this_set|
180
- if this_set.is_a?( ::ModuleCluster::ClusterStack::Set::MultiSetProxy )
181
- this_set.suspended
182
- else
183
- this_set.suspended ? true : false
184
- end
185
- end.flatten
186
- end
187
-
188
- ################
189
- # suspended= #
190
- ################
191
-
192
- def suspended=( true_or_false )
193
-
194
- self.each do |this_set|
195
- this_set.suspended = true_or_false
196
- end
197
-
198
- return true_or_false
199
-
200
- end
201
-
202
- #############
203
- # suspend #
204
- #############
205
-
206
- def suspend
207
- self.suspended = true
208
- end
209
-
210
- ############
211
- # resume #
212
- ############
213
-
214
- def resume
215
- self.suspended = false
216
- end
217
-
218
- ################
219
- # suspended? #
220
- ################
221
-
222
- def suspended?
223
- return suspended
224
- end
225
-
226
- ################
227
- # hooks_with #
228
- ################
229
-
230
- def hooks_with( descriptor_hash )
231
-
232
- matched_hooks = self.class.new
233
-
234
- # for each set
235
- self.each do |this_set|
236
-
237
- if this_set.respond_to?( __method__ )
238
-
239
- matched_hooks.concat( this_set.hooks_with( descriptor_hash ) )
240
-
241
- else
242
-
243
- # see if set matches descriptor
244
- matched = false
245
- descriptor_hash.each do |descriptor, description|
246
- case descriptor
247
-
248
- when :dependency_module
249
- if description.is_a?( Array )
250
- matched = description.include?( this_set.dependency_module )
251
- else
252
- matched = ( this_set.dependency_module == description )
253
- end
254
- break unless matched
255
-
256
- when :method
257
- if description.is_a?( Array )
258
- matched = description.include?( this_set.method )
259
- else
260
- matched = ( this_set.method == description )
261
- end
262
- break unless matched
263
-
264
- when :module_class_instance_or_all
265
- case this_set.module_class_instance_or_all
266
- when :all, :module_or_class_or_instance, :module_and_class_and_instance,
267
- :module_class_or_instance, :module_class_and_instance, :module_class_instance
268
- matched = true
269
- when :module_or_class, :module_and_class, :module_class
270
- case description
271
- when :module, :class
272
- matched = true
273
- else
274
- matched = false
275
- end
276
- when :module_or_instance, :module_and_instance, :module_instance
277
- case description
278
- when :module, :instance
279
- matched = true
280
- else
281
- matched = false
282
- end
283
- when :class_or_instance, :class_and_instance, :class_instance
284
- case description
285
- when :class, :instance
286
- matched = true
287
- else
288
- matched = false
289
- end
290
- when :module, :class, :instance
291
- matched = ( this_set.module_class_instance_or_all == description )
292
- end
293
- break unless matched
294
-
295
- when :include_or_extend
296
- case this_set.include_or_extend
297
- when :include_and_extend
298
- matched = true
299
- else
300
- matched = ( this_set.include_or_extend == description )
301
- end
302
- break unless matched
303
-
304
- when :modules
305
- if description.is_a?( Array )
306
- matched = this_set.modules.include?( *description )
307
- else
308
- matched = this_set.modules.include?( description )
309
- end
310
- break unless matched
311
-
312
- when :runtime_includes_or_extends_block
313
- break unless matched = ( this_set.runtime_includes_or_extends_block == description )
314
-
315
- when :suspended
316
- break unless matched = ( ( this_set.suspended ||= false ) == description )
317
-
318
- when :name
319
- if description.is_a?( Array )
320
- matched = description.include?( this_set.name )
321
- else
322
- matched = ( this_set.name == description )
323
- end
324
- break unless matched
325
-
326
- end
327
- end
328
- # if it does, add it to our return set
329
- matched_hooks.push( this_set ) if matched
330
- end
331
-
332
- end
333
-
334
- return matched_hooks
335
-
336
- end
337
-
338
- ###########
339
- # hooks #
340
- ###########
341
-
342
- def hooks( hook_name )
343
-
344
- matched_hooks = self.class.new
345
-
346
- # for each set
347
- self.each do |this_set|
348
- if this_set.is_a?( ::ModuleCluster::ClusterStack::Set::MultiSetProxy )
349
- matched_hooks.concat( this_set.hooks( hook_name ) )
350
- else
351
- matched_hooks.push( this_set ) if this_set.name == hook_name
352
- end
353
- end
354
-
355
- return matched_hooks
356
-
357
- end
358
-
359
- end