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,153 +0,0 @@
1
-
2
- module ::ModuleCluster::Suspend::WithoutHooks
3
-
4
- include ::ModuleCluster::Suspend::Hooks
5
-
6
- #######################
7
- # without_any_hooks #
8
- #######################
9
-
10
- def without_any_hooks( description = nil )
11
- if description
12
- # we don't want to end up unsuspending any sets that were already suspended
13
- # so we add to the description only sets that are not suspended
14
- description[ :suspended ] = false
15
- sets = cluster_stack.all_hooks.hooks_with( description )
16
- sets.suspend
17
- yield
18
- sets.resume
19
- else
20
- cluster_stack.suspend_any_hooks
21
- yield
22
- cluster_stack.resume_any_hooks
23
- end
24
- return self
25
- end
26
-
27
- ###############################
28
- # without_any_include_hooks #
29
- ###############################
30
-
31
- def without_any_include_hooks( description = nil )
32
- if description
33
- # we don't want to end up unsuspending any sets that were already suspended
34
- # so we add to the description only sets that are not suspended
35
- description[ :suspended ] = false
36
- sets = cluster_stack.all_include_hooks.hooks_with( description )
37
- sets.suspend
38
- yield
39
- sets.resume
40
- else
41
- cluster_stack.suspend_any_include_hooks
42
- yield
43
- cluster_stack.resume_any_include_hooks
44
- end
45
- return self
46
- end
47
-
48
- ##############################
49
- # without_any_extend_hooks #
50
- ##############################
51
-
52
- def without_any_extend_hooks( description = nil )
53
- if description
54
- # we don't want to end up unsuspending any sets that were already suspended
55
- # so we add to the description only sets that are not suspended
56
- description[ :suspended ] = false
57
- sets = cluster_stack.all_extend_hooks.hooks_with( description )
58
- sets.suspend
59
- yield
60
- sets.resume
61
- else
62
- cluster_stack.suspend_any_extend_hooks
63
- yield
64
- cluster_stack.resume_any_extend_hooks
65
- end
66
- return self
67
- end
68
-
69
- ###########################
70
- # without_include_hooks #
71
- ###########################
72
-
73
- def without_include_hooks( description = nil )
74
- if description
75
- # we don't want to end up unsuspending any sets that were already suspended
76
- # so we add to the description only sets that are not suspended
77
- description[ :suspended ] = false
78
- sets = cluster_stack.include_hooks.hooks_with( description )
79
- sets.suspend
80
- yield
81
- sets.resume
82
- else
83
- cluster_stack.suspend_include_hooks
84
- yield
85
- cluster_stack.resume_include_hooks
86
- end
87
- return self
88
- end
89
-
90
- ##########################
91
- # without_extend_hooks #
92
- ##########################
93
-
94
- def without_extend_hooks( description = nil )
95
- if description
96
- # we don't want to end up unsuspending any sets that were already suspended
97
- # so we add to the description only sets that are not suspended
98
- description[ :suspended ] = false
99
- sets = cluster_stack.extend_hooks.hooks_with( description )
100
- sets.suspend
101
- yield
102
- sets.resume
103
- else
104
- cluster_stack.suspend_extend_hooks
105
- yield
106
- cluster_stack.resume_extend_hooks
107
- end
108
- return self
109
- end
110
-
111
- ###################################
112
- # without_prepend_include_hooks #
113
- ###################################
114
-
115
- def without_prepend_include_hooks( description = nil )
116
- if description
117
- # we don't want to end up unsuspending any sets that were already suspended
118
- # so we add to the description only sets that are not suspended
119
- description[ :suspended ] = false
120
- sets = cluster_stack.prepend_include_hooks.hooks_with( description )
121
- sets.suspend
122
- yield
123
- sets.resume
124
- else
125
- cluster_stack.suspend_prepend_include_hooks
126
- yield
127
- cluster_stack.resume_prepend_include_hooks
128
- end
129
- return self
130
- end
131
-
132
- ##################################
133
- # without_prepend_extend_hooks #
134
- ##################################
135
-
136
- def without_prepend_extend_hooks( description = nil )
137
- if description
138
- # we don't want to end up unsuspending any sets that were already suspended
139
- # so we add to the description only sets that are not suspended
140
- description[ :suspended ] = false
141
- sets = cluster_stack.prepend_extend_hooks.hooks_with( description )
142
- sets.suspend
143
- yield
144
- sets.resume
145
- else
146
- cluster_stack.suspend_prepend_extend_hooks
147
- yield
148
- cluster_stack.resume_prepend_extend_hooks
149
- end
150
- return self
151
- end
152
-
153
- end
@@ -1,77 +0,0 @@
1
-
2
- module ::ModuleCluster::CascadeFeatures
3
-
4
- extend ::ModuleCluster::CascadeFeatures::PerformCascades
5
-
6
- #####################
7
- # append_features #
8
- #####################
9
-
10
- def append_features( hooked_instance )
11
-
12
- ::ModuleCluster::CascadeFeatures.perform_cascades( self,
13
- :prepend_include,
14
- hooked_instance,
15
- cluster_stack.prepend_include_hooks )
16
-
17
- super
18
-
19
- end
20
-
21
- ##############
22
- # included #
23
- ##############
24
-
25
- def included( hooked_instance )
26
-
27
- super
28
-
29
- ::ModuleCluster::CascadeFeatures.perform_cascades( self,
30
- :include,
31
- hooked_instance,
32
- cluster_stack.include_hooks )
33
-
34
- # if we are included in a class and we have cascading inherit hooks we need to move them over
35
- # append_features and included are both called for an inlucde, so we only need to do this in one
36
- if hooked_instance.is_a?( Class )
37
-
38
- unless cluster_stack.inherited_hooks.empty?
39
- hooked_instance.extend( ::ModuleCluster::Define::Block::Subclass )
40
- hooked_instance.cluster_stack.inherited_hooks.concat( cluster_stack.inherited_hooks )
41
- end
42
-
43
- end
44
-
45
- end
46
-
47
- ###################
48
- # extend_object #
49
- ###################
50
-
51
- def extend_object( hooked_instance )
52
-
53
- ::ModuleCluster::CascadeFeatures.perform_cascades( self,
54
- :prepend_extend,
55
- hooked_instance,
56
- cluster_stack.prepend_extend_hooks )
57
-
58
- super
59
-
60
- end
61
-
62
- ##############
63
- # extended #
64
- ##############
65
-
66
- def extended( hooked_instance )
67
-
68
- super
69
-
70
- ::ModuleCluster::CascadeFeatures.perform_cascades( self,
71
- :extend,
72
- hooked_instance,
73
- cluster_stack.extend_hooks )
74
-
75
- end
76
-
77
- end
@@ -1,44 +0,0 @@
1
-
2
- module ::ModuleCluster::CascadeFeatures::ClusterStack
3
-
4
- #########################
5
- # self.cluster_stacks #
6
- #########################
7
-
8
- def self.cluster_stacks
9
-
10
- return @cluster_stacks ||= Hash.new
11
-
12
- end
13
-
14
- ########################
15
- # self.cluster_stack #
16
- ########################
17
-
18
- def self.cluster_stack( class_or_module )
19
-
20
- cluster_stack_for_class_or_module = nil
21
-
22
- unless cluster_stack_for_class_or_module = cluster_stacks[ class_or_module ]
23
-
24
- cluster_stack_for_class_or_module = ::ModuleCluster::ClusterStack.new
25
-
26
- cluster_stacks[ class_or_module ] = cluster_stack_for_class_or_module
27
-
28
- end
29
-
30
- return cluster_stack_for_class_or_module
31
-
32
- end
33
-
34
- ###################
35
- # cluster_stack #
36
- ###################
37
-
38
- def cluster_stack
39
-
40
- return ::ModuleCluster::CascadeFeatures::ClusterStack.cluster_stack( self )
41
-
42
- end
43
-
44
- end
@@ -1,292 +0,0 @@
1
-
2
- module ::ModuleCluster::CascadeFeatures::PerformCascades
3
-
4
- ######################
5
- # perform_cascades #
6
- ######################
7
-
8
- def perform_cascades( module_self, action, hooked_instance, set_stack )
9
-
10
- # This method is called when a ::ModuleCluster module is included or extended.
11
- # It determines what modules should be included/extended and which should cascade.
12
-
13
- unless module_self.hooks_suspended?( action )
14
-
15
- # for each set:
16
- set_stack.each do |this_set|
17
-
18
- # if this particular set is suspended, skip to the next
19
- next if this_set.suspended
20
-
21
- # Block sets simply run a block at a hook.
22
- # They do not include or extend returns from the block.
23
- # The hooked module will not be extended by ::ModuleCluster.
24
- if this_set.is_a?( ::ModuleCluster::ClusterStack::Block::Set )
25
-
26
- # if our blocks are set to cascade then we need to copy inherit hooks
27
- if this_set.dependency_module.should_cascade?( hooked_instance )
28
- cascade_block_into_hooked_instance( module_self, action, hooked_instance, this_set )
29
- end
30
-
31
- if this_set.dependency_module.should_run_block?( hooked_instance )
32
-
33
- case this_set.runtime_block.arity
34
- when 0
35
- module_self.instance_eval( & this_set.runtime_block )
36
- else
37
- module_self.instance_exec( hooked_instance, & this_set.runtime_block )
38
- end
39
-
40
- end
41
-
42
- # Other sets take parameters and an optional block. The optional block returns are included
43
- # or extended like the parameters provided.
44
- else
45
-
46
- if should_cascade = this_set.dependency_module.should_cascade?( hooked_instance )
47
- # cascade parameter modules as appropriate
48
- cascade_modules_into_hooked_instance( module_self,
49
- hooked_instance,
50
- this_set,
51
- this_set.modules )
52
- end
53
-
54
- # dependency modules can cause instances to be included/extended and/or cascade
55
- should_include = this_set.dependency_module.should_include_or_extend?( hooked_instance )
56
-
57
- # include/extend parameter modules as appropriate
58
- if should_include
59
- include_extend_modules( module_self, hooked_instance, this_set, this_set.modules )
60
- end
61
-
62
- # process runtime block if present
63
- if this_set.runtime_includes_or_extends_block
64
-
65
- # if we have a runtime block, run block and collect returns as appropriate
66
- if runtime_modules = collect_block_runtime_result_modules( module_self,
67
- hooked_instance,
68
- this_set )
69
-
70
- # cascade return modules if appropriate
71
- if should_cascade
72
- cascade_modules_into_hooked_instance( module_self,
73
- hooked_instance,
74
- this_set,
75
- runtime_modules )
76
- end
77
-
78
- # include/extend return modules if appropriate
79
- if should_include
80
- include_extend_modules( module_self, hooked_instance, this_set, runtime_modules )
81
- end
82
-
83
- end
84
-
85
- end
86
-
87
- end
88
-
89
- end
90
-
91
- end
92
-
93
- end
94
-
95
- ############################
96
- # include_extend_modules #
97
- ############################
98
-
99
- def include_extend_modules( module_self, hooked_instance, set, modules )
100
-
101
- # Collect include/extend modules from this set into our eventual include/extend order.
102
- case set.include_or_extend
103
- when :include_and_extend
104
- include_or_extend_hooked_instance( hooked_instance, set, true, true, modules )
105
- when :include
106
- include_or_extend_hooked_instance( hooked_instance, set, true, false, modules )
107
- when :extend
108
- include_or_extend_hooked_instance( hooked_instance, set, false, true, modules )
109
- end
110
-
111
- end
112
-
113
- ##########################################
114
- # cascade_modules_into_hooked_instance #
115
- ##########################################
116
-
117
- def cascade_modules_into_hooked_instance( module_self, hooked_instance, set, modules )
118
-
119
- # if we are supposed to cascade we need to extend with the ::ModuleCluster dependency module
120
- hooked_instance.extend( set.dependency_module )
121
-
122
- # and we call the set's definition method to cascade
123
- hooked_instance.__send__( set.method, *modules )
124
-
125
- end
126
-
127
- ########################################
128
- # cascade_block_into_hooked_instance #
129
- ########################################
130
-
131
- def cascade_block_into_hooked_instance( module_self, action, hooked_instance, set )
132
-
133
- hooked_instance.extend( set.dependency_module )
134
-
135
- if hooked_instance.is_a?( Class )
136
-
137
- if action == :inherited
138
-
139
- unless set.dependency_module == ::ModuleCluster::CascadeFeatures::Subclass
140
- hooked_instance.extend( ::ModuleCluster::CascadeFeatures::Subclass )
141
- end
142
-
143
- hooked_instance.subclass( & set.runtime_block )
144
-
145
- end
146
-
147
- else
148
-
149
- # and we call the set's definition method to cascade
150
- hooked_instance.__send__( set.method, & set.runtime_block )
151
-
152
- end
153
-
154
- end
155
-
156
- #######################################
157
- # include_or_extend_hooked_instance #
158
- ######################################
159
-
160
- def include_or_extend_hooked_instance( hooked_instance,
161
- set,
162
- should_include,
163
- should_extend,
164
- modules )
165
-
166
- # We have collected includes, extends, transparent cascades.
167
- # Now we want to actually include/extend/cascade as appropriate.
168
-
169
- # If we have a module (a class is a module):
170
- module_self = self
171
- if hooked_instance.is_a?( Module )
172
-
173
- hooked_instance.module_eval do
174
-
175
- if should_include and
176
- module_self.should_include_or_extend_instance?( set.module_class_instance_or_all,
177
- hooked_instance ) and
178
- ! modules.empty?
179
-
180
- include( *modules.reverse )
181
-
182
- end
183
-
184
- if should_extend and
185
- module_self.should_include_or_extend_instance?( set.module_class_instance_or_all,
186
- hooked_instance ) and
187
- ! modules.empty?
188
-
189
- extend( *modules.reverse )
190
-
191
- end
192
-
193
- end
194
-
195
- # Otherwise we have an instance:
196
- else
197
-
198
- if should_extend and
199
- module_self.should_include_or_extend_instance?( set.module_class_instance_or_all,
200
- hooked_instance ) and
201
- ! modules.empty?
202
-
203
- hooked_instance.extend( *modules.reverse )
204
-
205
- end
206
-
207
- end
208
-
209
- end
210
-
211
- ########################################
212
- # should_include_or_extend_instance? #
213
- ########################################
214
-
215
- def should_include_or_extend_instance?( module_class_instance_or_all, into_instance )
216
-
217
- # The set stack already corresponds to include or extend or both,
218
- # we are testing all_module_class_or_instance for:
219
- #
220
- # * any include/extend
221
- # * module include/extend
222
- # * class include/extend
223
- # * instance extend
224
-
225
- should_include_or_extend_instance = false
226
-
227
- case module_class_instance_or_all
228
- when :all, :module_or_class_or_instance, :module_and_class_and_instance,
229
- :module_class_or_instance, :module_class_and_instance, :module_class_instance
230
- should_include_or_extend_instance = true
231
- when :module_or_class, :module_and_class, :module_class
232
- should_include_or_extend_instance = into_instance.is_a?( Module )
233
- when :module_or_instance, :module_and_instance, :module_instance
234
- should_include_or_extend_instance = ( ! into_instance.is_a?( Module ) or
235
- ( into_instance.is_a?( Module ) &&
236
- ! into_instance.is_a?( Class ) ) )
237
- when :class_or_instance, :class_and_instance, :class_instance
238
- should_include_or_extend_instance = ( into_instance.is_a?( Class ) or
239
- ! into_instance.is_a?( Module ) )
240
- when :module
241
- should_include_or_extend_instance = ( into_instance.is_a?( Module ) &&
242
- ! into_instance.is_a?( Class ) )
243
- when :class
244
- should_include_or_extend_instance = into_instance.is_a?( Class )
245
- when :instance
246
- should_include_or_extend_instance = ! into_instance.is_a?( Module )
247
- end
248
-
249
- return should_include_or_extend_instance
250
-
251
- end
252
-
253
- ##########################################
254
- # collect_block_runtime_result_modules #
255
- ##########################################
256
-
257
- def collect_block_runtime_result_modules( module_self, hooked_instance, set )
258
-
259
- runtime_block_result_modules = nil
260
-
261
- block = set.runtime_includes_or_extends_block
262
-
263
- case block.arity
264
- when 0
265
- runtime_block_result_modules = module_self.instance_eval( & block )
266
- else
267
- runtime_block_result_modules = module_self.instance_exec( hooked_instance,
268
- & block )
269
- end
270
-
271
- if runtime_block_result_modules
272
-
273
- # make sure we have an array as a result
274
- unless runtime_block_result_modules.is_a?( Array )
275
- runtime_block_result_modules = [ runtime_block_result_modules ]
276
- end
277
-
278
- # make sure members of our result array are modules
279
- runtime_block_result_modules.delete_if do |this_result_instance|
280
- ! this_result_instance.is_a?( Module )
281
- end
282
-
283
-
284
- runtime_block_result_modules = nil if runtime_block_result_modules.empty?
285
-
286
- end
287
-
288
- return runtime_block_result_modules
289
-
290
- end
291
-
292
- end