module-cluster 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,359 @@
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
@@ -0,0 +1,55 @@
1
+
2
+ module ModuleCluster::ClusterStack::Status
3
+
4
+ ###############
5
+ # all_hooks #
6
+ ###############
7
+
8
+ def all_hooks
9
+ return @all_hooks ||= ::ModuleCluster::ClusterStack::Set::MultiSetProxy.new( all_include_hooks, all_extend_hooks )
10
+ end
11
+
12
+ #######################
13
+ # all_include_hooks #
14
+ #######################
15
+
16
+ def all_include_hooks
17
+ return @all_include_hooks ||= ::ModuleCluster::ClusterStack::Set::MultiSetProxy.new( prepend_include_hooks, include_hooks )
18
+ end
19
+
20
+ ######################
21
+ # all_extend_hooks #
22
+ #######################
23
+
24
+ def all_extend_hooks
25
+ return @all_extend_hooks ||= ::ModuleCluster::ClusterStack::Set::MultiSetProxy.new( prepend_extend_hooks, extend_hooks )
26
+ end
27
+
28
+ ###################
29
+ # has_any_hook? #
30
+ ###################
31
+
32
+ def has_any_hook?( description )
33
+ hooks = all_hooks.hooks_with( description )
34
+ return hooks ||= false
35
+ end
36
+
37
+ ###########################
38
+ # has_any_include_hook? #
39
+ ###########################
40
+
41
+ def has_any_include_hook?( description )
42
+ hooks = all_include_hooks.hooks_with( description )
43
+ return hooks ||= false
44
+ end
45
+
46
+ ##########################
47
+ # has_any_extend_hook? #
48
+ ##########################
49
+
50
+ def has_any_extend_hook?( description )
51
+ hooks = all_extend_hooks.hooks_with( description )
52
+ return hooks ||= false
53
+ end
54
+
55
+ end
@@ -0,0 +1,199 @@
1
+
2
+ module ModuleCluster::ClusterStack::Suspend
3
+
4
+ #######################
5
+ # suspend_any_hooks #
6
+ #######################
7
+
8
+ def suspend_any_hooks
9
+ @all_hooks_suspended = true
10
+ end
11
+
12
+ ###############################
13
+ # suspend_any_include_hooks #
14
+ ###############################
15
+
16
+ def suspend_any_include_hooks
17
+ @all_include_hooks_suspended = true
18
+ end
19
+
20
+ ##############################
21
+ # suspend_any_extend_hooks #
22
+ ##############################
23
+
24
+ def suspend_any_extend_hooks
25
+ @all_extend_hooks_suspended = true
26
+ end
27
+
28
+ ###########################
29
+ # suspend_include_hooks #
30
+ ###########################
31
+
32
+ def suspend_include_hooks
33
+ @include_hooks_suspended = true
34
+ end
35
+
36
+ ##########################
37
+ # suspend_extend_hooks #
38
+ ##########################
39
+
40
+ def suspend_extend_hooks
41
+ @extend_hooks_suspended = true
42
+ end
43
+
44
+ ###################################
45
+ # suspend_prepend_include_hooks #
46
+ ###################################
47
+
48
+ def suspend_prepend_include_hooks
49
+ @prepend_include_hooks_suspended = true
50
+ end
51
+
52
+ ##################################
53
+ # suspend_prepend_extend_hooks #
54
+ ##################################
55
+
56
+ def suspend_prepend_extend_hooks
57
+ @prepend_extend_hooks_suspended = true
58
+ end
59
+
60
+ ######################
61
+ # hooks_suspended? #
62
+ ######################
63
+
64
+ def hooks_suspended?( action )
65
+
66
+ return true if all_hooks_suspended?
67
+
68
+ case action
69
+ when :include
70
+ return true if all_include_hooks_suspended?
71
+ return true if include_hooks_suspended?
72
+ when :extend
73
+ return true if all_extend_hooks_suspended?
74
+ return true if extend_hooks_suspended?
75
+ when :prepend_include
76
+ return true if all_include_hooks_suspended?
77
+ return true if prepend_include_hooks_suspended?
78
+ when :prepend_extend
79
+ return true if all_extend_hooks_suspended?
80
+ return true if prepend_extend_hooks_suspended?
81
+ end
82
+
83
+ return false
84
+
85
+ end
86
+
87
+ ##########################
88
+ # all_hooks_suspended? #
89
+ ##########################
90
+
91
+ def all_hooks_suspended?
92
+ return @all_hooks_suspended ||= false
93
+ end
94
+
95
+ ##################################
96
+ # all_include_hooks_suspended? #
97
+ ##################################
98
+
99
+ def all_include_hooks_suspended?
100
+ return ( @all_include_hooks_suspended ||= false ) || all_hooks_suspended?
101
+ end
102
+
103
+ #################################
104
+ # all_extend_hooks_suspended? #
105
+ #################################
106
+
107
+ def all_extend_hooks_suspended?
108
+ return ( @all_extend_hooks_suspended ||= false ) || all_hooks_suspended?
109
+ end
110
+
111
+ ##############################
112
+ # include_hooks_suspended? #
113
+ ##############################
114
+
115
+ def include_hooks_suspended?
116
+ return ( @include_hooks_suspended ||= false ) || all_include_hooks_suspended?
117
+ end
118
+
119
+ #############################
120
+ # extend_hooks_suspended? #
121
+ #############################
122
+
123
+ def extend_hooks_suspended?
124
+ return ( @extend_hooks_suspended ||= false ) || all_extend_hooks_suspended?
125
+ end
126
+
127
+ ######################################
128
+ # prepend_include_hooks_suspended? #
129
+ ######################################
130
+
131
+ def prepend_include_hooks_suspended?
132
+ return ( @prepend_include_hooks_suspended ||= false ) || all_include_hooks_suspended?
133
+ end
134
+
135
+ #####################################
136
+ # prepend_extend_hooks_suspended? #
137
+ #####################################
138
+
139
+ def prepend_extend_hooks_suspended?
140
+ return ( @prepend_extend_hooks_suspended ||= false ) || all_extend_hooks_suspended?
141
+ end
142
+
143
+ ######################
144
+ # resume_any_hooks #
145
+ ######################
146
+
147
+ def resume_any_hooks
148
+ @all_hooks_suspended = false
149
+ end
150
+
151
+ ##############################
152
+ # resume_any_include_hooks #
153
+ ##############################
154
+
155
+ def resume_any_include_hooks
156
+ @all_include_hooks_suspended = false
157
+ end
158
+
159
+ #############################
160
+ # resume_any_extend_hooks #
161
+ #############################
162
+
163
+ def resume_any_extend_hooks
164
+ @all_extend_hooks_suspended = false
165
+ end
166
+
167
+ ##########################
168
+ # resume_include_hooks #
169
+ ##########################
170
+
171
+ def resume_include_hooks
172
+ @include_hooks_suspended = false
173
+ end
174
+
175
+ #########################
176
+ # resume_extend_hooks #
177
+ #########################
178
+
179
+ def resume_extend_hooks
180
+ @extend_hooks_suspended = false
181
+ end
182
+
183
+ ##################################
184
+ # resume_prepend_include_hooks #
185
+ ##################################
186
+
187
+ def resume_prepend_include_hooks
188
+ @prepend_include_hooks_suspended = false
189
+ end
190
+
191
+ #################################
192
+ # resume_prepend_extend_hooks #
193
+ #################################
194
+
195
+ def resume_prepend_extend_hooks
196
+ @prepend_extend_hooks_suspended = false
197
+ end
198
+
199
+ end