module-cluster 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/README.md +146 -1
  2. data/README.rdoc +146 -1
  3. data/lib/module-cluster.rb +54 -12
  4. data/lib/module-cluster/ModuleCluster/Define/Block.rb +3 -0
  5. data/lib/module-cluster/ModuleCluster/Define/Block/Class.rb +16 -4
  6. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb +63 -0
  7. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModule.rb +2 -0
  8. data/lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrInstance.rb +63 -0
  9. data/lib/module-cluster/ModuleCluster/Define/Block/Instance.rb +32 -0
  10. data/lib/module-cluster/ModuleCluster/Define/Block/Module.rb +16 -4
  11. data/lib/module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb +63 -0
  12. data/lib/module-cluster/ModuleCluster/Define/ClassCluster.rb +200 -0
  13. data/lib/module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb +127 -0
  14. data/lib/module-cluster/ModuleCluster/Define/Cluster.rb +7 -19
  15. data/lib/module-cluster/ModuleCluster/Define/ClusterCascades.rb +5 -20
  16. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb +9 -26
  17. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb +9 -26
  18. data/lib/module-cluster/ModuleCluster/Define/InstanceCluster.rb +46 -0
  19. data/lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb +200 -0
  20. data/lib/module-cluster/ModuleCluster/Define/ModuleOrClassCluster.rb +208 -0
  21. data/lib/module-cluster/ModuleCluster/Define/ModuleOrInstanceCluster.rb +127 -0
  22. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures.rb +54 -0
  23. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb +44 -0
  24. data/lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb +209 -0
  25. data/lib/module-cluster/{ModuleCluster → _private_/ModuleCluster}/ClusterStack.rb +0 -2
  26. data/lib/module-cluster/{ModuleCluster → _private_/ModuleCluster}/ClusterStack/Block.rb +1 -2
  27. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb +36 -0
  28. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb +20 -0
  29. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb +36 -0
  30. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb +2 -0
  31. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb +108 -0
  32. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Includes.rb +84 -0
  33. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb +108 -0
  34. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb +84 -0
  35. data/lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb +7 -0
  36. data/lib/module-cluster/{ModuleCluster → _private_/ModuleCluster}/ExtendForCascade.rb +0 -0
  37. data/spec/ModuleCluster/Define/Block/ClassOrInstance_spec.rb +230 -0
  38. data/spec/ModuleCluster/Define/Block/ClassOrModuleOrInstance_spec.rb +238 -0
  39. data/spec/ModuleCluster/Define/Block/ClassOrModule_spec.rb +231 -0
  40. data/spec/ModuleCluster/Define/Block/Class_spec.rb +224 -0
  41. data/spec/ModuleCluster/Define/Block/Instance_spec.rb +78 -0
  42. data/spec/ModuleCluster/Define/Block/ModuleOrInstance_spec.rb +54 -0
  43. data/spec/ModuleCluster/Define/Block/Module_spec.rb +224 -0
  44. data/spec/ModuleCluster/Define/Block_spec.rb +18 -0
  45. data/spec/ModuleCluster/Define/ClassCluster_spec.rb +728 -0
  46. data/spec/ModuleCluster/Define/ClassOrInstanceCluster_spec.rb +576 -0
  47. data/spec/ModuleCluster/Define/ClusterCascadesToClass_spec.rb +298 -60
  48. data/spec/ModuleCluster/Define/ClusterCascadesToModule_spec.rb +307 -61
  49. data/spec/ModuleCluster/Define/ClusterCascades_spec.rb +335 -36
  50. data/spec/ModuleCluster/Define/Cluster_spec.rb +447 -14
  51. data/spec/ModuleCluster/Define/InstanceCluster_spec.rb +102 -0
  52. data/spec/ModuleCluster/Define/ModuleCluster_spec.rb +728 -0
  53. data/spec/ModuleCluster/Define/ModuleOrClassCluster_spec.rb +728 -0
  54. data/spec/ModuleCluster/Define/ModuleOrInstanceCluster_spec.rb +576 -0
  55. data/spec/_private_/ModuleCluster/CascadeFeatures/PerformCascades_spec.rb +278 -0
  56. metadata +42 -13
  57. data/lib/module-cluster/ModuleCluster/CascadeFeatures.rb +0 -197
  58. data/lib/module-cluster/ModuleCluster/ClusterStack/Block/Class.rb +0 -36
  59. data/lib/module-cluster/ModuleCluster/ClusterStack/Block/Module.rb +0 -36
  60. data/lib/module-cluster/ModuleCluster/ClusterStack/Extends.rb +0 -29
  61. data/lib/module-cluster/ModuleCluster/ClusterStack/Includes.rb +0 -28
  62. data/lib/module-cluster/ModuleCluster/ClusterStack/PrependsExtends.rb +0 -28
  63. data/lib/module-cluster/ModuleCluster/ClusterStack/PrependsIncludes.rb +0 -28
  64. data/lib/module-cluster/ModuleCluster/Define/ClusterStack.rb +0 -26
@@ -0,0 +1,278 @@
1
+
2
+ require_relative '../../../../lib/module-cluster.rb'
3
+
4
+ describe ModuleCluster::CascadeFeatures::PerformCascades do
5
+
6
+ ##########################################
7
+ # collect_block_runtime_result_modules #
8
+ ##########################################
9
+
10
+ it 'can run a block and return any modules that were returned by the block' do
11
+ # condition is a ModuleCluster-extended module
12
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule01
13
+ end
14
+ # a module to be included/extended at hook time
15
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule01
16
+ end
17
+ # another module includes the first module and invokes the runtime hook
18
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule01
19
+ end
20
+ # we need a mock instance to use our methods
21
+ module ModuleCluster::CascadeFeatures::PerformCascades::Mock01
22
+ extend ModuleCluster::CascadeFeatures::PerformCascades
23
+ end
24
+ module_self = ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule01
25
+ hooked_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule01
26
+ block_ran = false
27
+ runtime_includes_block = Proc.new { block_ran = true ; ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule01 }
28
+ set = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include, nil, runtime_includes_block )
29
+ result_modules = ModuleCluster::CascadeFeatures::PerformCascades::Mock01.collect_block_runtime_result_modules( module_self,
30
+ hooked_instance,
31
+ set )
32
+ block_ran.should == true
33
+ result_modules.should == [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule01 ]
34
+ end
35
+
36
+ ########################################
37
+ # should_include_or_extend_instance? #
38
+ ########################################
39
+
40
+ it 'can report whether an instance should be included or extended based on a descriptor symbol' do
41
+ module ModuleCluster::CascadeFeatures::PerformCascades::Mock02
42
+ extend ModuleCluster::CascadeFeatures::PerformCascades
43
+ end
44
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleInstance02
45
+ end
46
+ class ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02
47
+ end
48
+
49
+ module_class_instance_or_all = :all
50
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleInstance02
51
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == true
52
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02
53
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == true
54
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02.new
55
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == true
56
+ module_class_instance_or_all = :module
57
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleInstance02
58
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == true
59
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02
60
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == false
61
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02.new
62
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == false
63
+ module_class_instance_or_all = :class
64
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleInstance02
65
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == false
66
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02
67
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == true
68
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02.new
69
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == false
70
+ module_class_instance_or_all = :instance
71
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleInstance02
72
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == false
73
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02
74
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == false
75
+ into_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockClassInstance02.new
76
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock02.should_include_or_extend_instance?( module_class_instance_or_all, into_instance ).should == true
77
+ end
78
+
79
+ #######################################
80
+ # include_or_extend_hooked_instance #
81
+ #######################################
82
+
83
+ it 'can include or extend the hooked instance as appropriate' do
84
+ # condition is a ModuleCluster-extended module
85
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule03
86
+ end
87
+ # a module to be included/extended at hook time
88
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03
89
+ end
90
+ # another module includes the first module and invokes the runtime hook
91
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03A
92
+ end
93
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03B
94
+ end
95
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03C
96
+ end
97
+ # we need a mock instance to use our methods
98
+ module ModuleCluster::CascadeFeatures::PerformCascades::Mock03
99
+ extend ModuleCluster::CascadeFeatures::PerformCascades
100
+ end
101
+ module_self = ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule03
102
+ set = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ] )
103
+
104
+ # include
105
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock03.include_or_extend_hooked_instance( ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03A,
106
+ set,
107
+ true,
108
+ false,
109
+ set.modules )
110
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03A.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ).should == true
111
+ eigenclass = class << ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03A ; self ; end
112
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ).should == false
113
+ # extend
114
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock03.include_or_extend_hooked_instance( ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03B,
115
+ set,
116
+ false,
117
+ true,
118
+ set.modules )
119
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03B.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ).should == false
120
+ eigenclass = class << ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03B ; self ; end
121
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ).should == true
122
+ # include and extend
123
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock03.include_or_extend_hooked_instance( ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03C,
124
+ set,
125
+ true,
126
+ true,
127
+ set.modules )
128
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03C.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ).should == true
129
+ eigenclass = class << ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule03C ; self ; end
130
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule03 ).should == true
131
+
132
+ end
133
+
134
+ ##########################################
135
+ # cascade_modules_into_hooked_instance #
136
+ ##########################################
137
+
138
+ it 'can cascade modules into the hooked instance as appropriate' do
139
+ # condition is a ModuleCluster-extended module
140
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule04
141
+ def declaration_method( modules )
142
+ @declaration_method_called = true
143
+ end
144
+ def called_declaration_method
145
+ return @declaration_method_called
146
+ end
147
+ end
148
+ # a module to be included/extended at hook time
149
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule04A
150
+ end
151
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule04B
152
+ end
153
+ # another module includes the first module and invokes the runtime hook
154
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule04
155
+ end
156
+ # we need a mock instance to use our methods
157
+ module ModuleCluster::CascadeFeatures::PerformCascades::Mock04
158
+ extend ModuleCluster::CascadeFeatures::PerformCascades
159
+ end
160
+ module_self = ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule04
161
+ hooked_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule04
162
+ block_ran = false
163
+ runtime_includes_block = Proc.new { block_ran = true ; ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule04B }
164
+ set = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule04A ], runtime_includes_block )
165
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock04.cascade_modules_into_hooked_instance( module_self, hooked_instance, set, set.modules )
166
+ # hooked instance should be extended with dependency module (module_self) and :declaration_method should be called on it
167
+ hooked_instance_eigenclass = class << hooked_instance ; self ; end
168
+ hooked_instance_eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule04 ).should == true
169
+ hooked_instance.called_declaration_method.should == true
170
+ end
171
+
172
+ ############################
173
+ # include_extend_modules #
174
+ ############################
175
+
176
+ it 'can perform include and/or extend of specified modules into instance' do
177
+ # condition is a ModuleCluster-extended module
178
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule05
179
+ end
180
+ # a module to be included/extended at hook time
181
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05
182
+ end
183
+ # another module includes the first module and invokes the runtime hook
184
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05A
185
+ end
186
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05B
187
+ end
188
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05C
189
+ end
190
+ # we need a mock instance to use our methods
191
+ module ModuleCluster::CascadeFeatures::PerformCascades::Mock05
192
+ extend ModuleCluster::CascadeFeatures::PerformCascades
193
+ end
194
+ module_self = ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule05
195
+
196
+ # include
197
+ set = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ] )
198
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock05.include_extend_modules( ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule05,
199
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05A,
200
+ set,
201
+ set.modules )
202
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05A.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ).should == true
203
+ eigenclass = class << ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05A ; self ; end
204
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ).should == false
205
+ # extend
206
+ set = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :extend, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ] )
207
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock05.include_extend_modules( ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule05,
208
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05B,
209
+ set,
210
+ set.modules )
211
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05B.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ).should == false
212
+ eigenclass = class << ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05B ; self ; end
213
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ).should == true
214
+ # include and extend
215
+ set = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include_and_extend, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ] )
216
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock05.include_extend_modules( ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule05,
217
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05C,
218
+ set,
219
+ set.modules )
220
+ ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05C.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ).should == true
221
+ eigenclass = class << ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule05C ; self ; end
222
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule05 ).should == true
223
+
224
+ end
225
+
226
+ ######################
227
+ # cascade_features #
228
+ ######################
229
+
230
+ it 'can perform cascade of specified modules into instance' do
231
+
232
+ # condition is a ModuleCluster-extended module
233
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule06
234
+ def self.should_include_or_extend?( hooked_instance )
235
+ return true
236
+ end
237
+ def self.should_cascade?( hooked_instance )
238
+ return true
239
+ end
240
+ def declaration_method( modules )
241
+ @declaration_method_called = true
242
+ end
243
+ def called_declaration_method
244
+ return @declaration_method_called
245
+ end
246
+ end
247
+ # a module to be included/extended at hook time
248
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06A
249
+ end
250
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06B
251
+ end
252
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06C
253
+ end
254
+ # another module includes the first module and invokes the runtime hook
255
+ module ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule06
256
+ end
257
+ # we need a mock instance to use our methods
258
+ module ModuleCluster::CascadeFeatures::PerformCascades::Mock06
259
+ extend ModuleCluster::CascadeFeatures::PerformCascades
260
+ end
261
+ module_self = ModuleCluster::CascadeFeatures::PerformCascades::MockCascadeModule06
262
+ hooked_instance = ModuleCluster::CascadeFeatures::PerformCascades::MockModuleIncludingMockCascadeModule06
263
+ set_one = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06A ] )
264
+ set_two = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :extend, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06B ] )
265
+ set_three = ModuleCluster::ClusterStack::Set.new( module_self, :declaration_method, :all, :include_and_extend, [ ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06C ] )
266
+ set_stack = [ set_one, set_two, set_three ]
267
+ ModuleCluster::CascadeFeatures::PerformCascades::Mock06.cascade_features( module_self, hooked_instance, set_stack )
268
+ hooked_instance.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06A ).should == true
269
+ hooked_instance.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06C ).should == true
270
+ eigenclass = class << hooked_instance ; self ; end
271
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06B ).should == true
272
+ eigenclass.ancestors.include?( ModuleCluster::CascadeFeatures::PerformCascades::MockHookedIncludeModule06C ).should == true
273
+ # also our dependency module should be extended
274
+ eigenclass.ancestors.include?( module_self ).should == true
275
+ hooked_instance.called_declaration_method.should == true
276
+ end
277
+
278
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: module-cluster
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.7
5
+ version: 1.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Asher
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-18 00:00:00 Z
13
+ date: 2011-12-22 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  description: "Provides methods for clustering modules so that when the main module is included other modules are also included or extended, either before or after the main module. There are currently three variants: cluster, cascade, cascade to class. Cluster causes the next module to be affected. Cascade causes all subsequent modules to be affected. Cascade to class causes the first including/extending class to be affected, but not any modules prior to it (although the effects will cascade through those unaffected modules)."
@@ -22,32 +22,61 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - lib/module-cluster/ModuleCluster/CascadeFeatures.rb
26
- - lib/module-cluster/ModuleCluster/ClusterStack/Block/Class.rb
27
- - lib/module-cluster/ModuleCluster/ClusterStack/Block/Module.rb
28
- - lib/module-cluster/ModuleCluster/ClusterStack/Block.rb
29
- - lib/module-cluster/ModuleCluster/ClusterStack/Extends.rb
30
- - lib/module-cluster/ModuleCluster/ClusterStack/Includes.rb
31
- - lib/module-cluster/ModuleCluster/ClusterStack/PrependsExtends.rb
32
- - lib/module-cluster/ModuleCluster/ClusterStack/PrependsIncludes.rb
33
- - lib/module-cluster/ModuleCluster/ClusterStack.rb
25
+ - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb
26
+ - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb
27
+ - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures.rb
28
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb
29
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb
30
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb
31
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb
32
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block.rb
33
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb
34
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Includes.rb
35
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb
36
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb
37
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb
38
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack.rb
39
+ - lib/module-cluster/_private_/ModuleCluster/ExtendForCascade.rb
34
40
  - lib/module-cluster/ModuleCluster/Define/Block/Class.rb
41
+ - lib/module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb
35
42
  - lib/module-cluster/ModuleCluster/Define/Block/ClassOrModule.rb
43
+ - lib/module-cluster/ModuleCluster/Define/Block/ClassOrModuleOrInstance.rb
44
+ - lib/module-cluster/ModuleCluster/Define/Block/Instance.rb
36
45
  - lib/module-cluster/ModuleCluster/Define/Block/Module.rb
46
+ - lib/module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb
37
47
  - lib/module-cluster/ModuleCluster/Define/Block.rb
48
+ - lib/module-cluster/ModuleCluster/Define/ClassCluster.rb
49
+ - lib/module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb
38
50
  - lib/module-cluster/ModuleCluster/Define/Cluster.rb
39
51
  - lib/module-cluster/ModuleCluster/Define/ClusterCascades.rb
40
52
  - lib/module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb
41
53
  - lib/module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb
42
- - lib/module-cluster/ModuleCluster/Define/ClusterStack.rb
43
54
  - lib/module-cluster/ModuleCluster/Define/Deprecated.rb
44
- - lib/module-cluster/ModuleCluster/ExtendForCascade.rb
55
+ - lib/module-cluster/ModuleCluster/Define/InstanceCluster.rb
56
+ - lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb
57
+ - lib/module-cluster/ModuleCluster/Define/ModuleOrClassCluster.rb
58
+ - lib/module-cluster/ModuleCluster/Define/ModuleOrInstanceCluster.rb
45
59
  - lib/module-cluster/ModuleCluster.rb
46
60
  - lib/module-cluster.rb
61
+ - spec/_private_/ModuleCluster/CascadeFeatures/PerformCascades_spec.rb
62
+ - spec/ModuleCluster/Define/Block/Class_spec.rb
63
+ - spec/ModuleCluster/Define/Block/ClassOrInstance_spec.rb
64
+ - spec/ModuleCluster/Define/Block/ClassOrModule_spec.rb
65
+ - spec/ModuleCluster/Define/Block/ClassOrModuleOrInstance_spec.rb
66
+ - spec/ModuleCluster/Define/Block/Instance_spec.rb
67
+ - spec/ModuleCluster/Define/Block/Module_spec.rb
68
+ - spec/ModuleCluster/Define/Block/ModuleOrInstance_spec.rb
69
+ - spec/ModuleCluster/Define/Block_spec.rb
70
+ - spec/ModuleCluster/Define/ClassCluster_spec.rb
71
+ - spec/ModuleCluster/Define/ClassOrInstanceCluster_spec.rb
47
72
  - spec/ModuleCluster/Define/Cluster_spec.rb
48
73
  - spec/ModuleCluster/Define/ClusterCascades_spec.rb
49
74
  - spec/ModuleCluster/Define/ClusterCascadesToClass_spec.rb
50
75
  - spec/ModuleCluster/Define/ClusterCascadesToModule_spec.rb
76
+ - spec/ModuleCluster/Define/InstanceCluster_spec.rb
77
+ - spec/ModuleCluster/Define/ModuleCluster_spec.rb
78
+ - spec/ModuleCluster/Define/ModuleOrClassCluster_spec.rb
79
+ - spec/ModuleCluster/Define/ModuleOrInstanceCluster_spec.rb
51
80
  - spec/ModuleCluster_spec.rb
52
81
  - README.md
53
82
  - README.rdoc
@@ -1,197 +0,0 @@
1
-
2
- module ModuleCluster::CascadeFeatures
3
-
4
- CascadeStruct = Struct.new( :includes, :extends, :cascades, :runtime_block )
5
- DependencyModule = Struct.new( :class_or_module, :method, :modules )
6
-
7
- #####################################################
8
- # self.get_runtime_includes_or_extends_from_block #
9
- #####################################################
10
-
11
- def self.get_runtime_includes_or_extends_from_block( module_self, class_or_module, include_or_extend, runtime_includes_or_extends_block )
12
-
13
- includes_or_extends = nil
14
-
15
- case runtime_includes_or_extends_block.arity
16
- when 0
17
- includes_or_extends = module_self.instance_eval( & runtime_includes_or_extends_block )
18
- else
19
- includes_or_extends = module_self.instance_exec( class_or_module, & runtime_includes_or_extends_block )
20
- end
21
-
22
- unless includes_or_extends.is_a?( Array )
23
- includes_or_extends = [ includes_or_extends ]
24
- end
25
-
26
- return includes_or_extends
27
-
28
- end
29
-
30
- #######################################
31
- # self.cascade_struct_for_set_stack #
32
- #######################################
33
-
34
- def self.cascade_struct_for_set_stack( module_self, class_or_module, set_stack )
35
-
36
- includes = Array.new
37
- extends = Array.new
38
- cascades = Hash.new
39
-
40
- set_stack.each do |this_set|
41
-
42
- if this_set.is_a?( ModuleCluster::ClusterStack::Block::Set )
43
-
44
- class_or_module.instance_eval do
45
- extend( ModuleCluster )
46
- end
47
-
48
- case this_set.runtime_block.arity
49
- when 0
50
- module_self.instance_eval( & this_set.runtime_block )
51
- else
52
- module_self.instance_exec( class_or_module, & this_set.runtime_block )
53
- end
54
-
55
- else
56
-
57
- # get cascades
58
- if this_set.dependency_module.should_cascade?( class_or_module )
59
- cascades[ this_set.dependency_module ] ||= Hash.new
60
- cascades[ this_set.dependency_module ][ this_set.method ] ||= Array.new
61
- cascades[ this_set.dependency_module ][ this_set.method ].concat( this_set.modules )
62
- end
63
-
64
- # get runtime block
65
- runtime_set = nil
66
- if block = this_set.runtime_includes_or_extends_block
67
- runtime_set = ModuleCluster::CascadeFeatures.get_runtime_includes_or_extends_from_block( module_self,
68
- class_or_module,
69
- this_set.include_or_extend,
70
- block )
71
- cascades[ this_set.dependency_module ] ||= Hash.new
72
- cascades[ this_set.dependency_module ][ this_set.method ] ||= Array.new
73
- cascades[ this_set.dependency_module ][ this_set.method ].concat( runtime_set )
74
- end
75
- # get includes/extends
76
- case this_set.include_or_extend
77
- when :include
78
- this_set.modules.each do |this_module|
79
- if this_set.dependency_module.should_include_or_extend?( class_or_module )
80
- includes.concat( this_set.modules )
81
- end
82
- end
83
- includes.concat( runtime_set ) if runtime_set
84
- when :extend
85
- if this_set.dependency_module.should_include_or_extend?( class_or_module )
86
- extends.concat( this_set.modules )
87
- end
88
- extends.concat( runtime_set ) if runtime_set
89
- end
90
-
91
- end
92
-
93
- end
94
-
95
- includes.uniq!
96
- includes.compact!
97
- extends.uniq!
98
- extends.compact!
99
- cascades.each do |this_dependency_module, this_method_and_module_set|
100
- this_method_and_module_set.each do |this_method, this_module_set|
101
- this_module_set.uniq!
102
- this_module_set.compact!
103
- end
104
- end
105
-
106
- return ModuleCluster::CascadeFeatures::CascadeStruct.new( includes, extends, cascades )
107
-
108
- end
109
-
110
- ###########################
111
- # self.cascade_features #
112
- ###########################
113
-
114
- def self.cascade_features( class_or_module, cascade_struct )
115
-
116
- if class_or_module.is_a?( Module )
117
-
118
- class_or_module.module_eval do
119
- include( *cascade_struct.includes.reverse ) unless cascade_struct.includes.empty?
120
- extend( *cascade_struct.extends.reverse ) unless cascade_struct.extends.empty?
121
- end
122
-
123
- cascade_struct.cascades.each do |this_dependency_module, this_method_and_module_set|
124
- this_method_and_module_set.each do |this_method, this_module_set|
125
- this_dependency_module.perform_cascades( class_or_module, this_method, this_module_set )
126
- end
127
- end
128
-
129
- else
130
-
131
- class_or_module.instance_eval do
132
- extend( *cascade_struct.extends.reverse ) unless cascade_struct.extends.empty?
133
- end
134
-
135
- cascade_struct.cascades.each do |this_dependency_module, this_method_and_module_set|
136
- this_method_and_module_set.each do |this_method, this_module_set|
137
- this_dependency_module.perform_cascades( class_or_module, :extend, this_module_set )
138
- end
139
- end
140
-
141
- end
142
-
143
- end
144
-
145
- #####################
146
- # append_features #
147
- #####################
148
-
149
- def append_features( class_or_module )
150
-
151
- cascade_struct = ModuleCluster::CascadeFeatures.cascade_struct_for_set_stack( self, class_or_module, cluster_stack.cascading_prepending_includes )
152
- ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
153
-
154
- super
155
-
156
- end
157
-
158
- ##############
159
- # included #
160
- ##############
161
-
162
- def included( class_or_module )
163
-
164
- super
165
-
166
- cascade_struct = ModuleCluster::CascadeFeatures.cascade_struct_for_set_stack( self, class_or_module, cluster_stack.cascading_includes )
167
- ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
168
-
169
- end
170
-
171
- ###################
172
- # extend_object #
173
- ###################
174
-
175
- def extend_object( class_or_module )
176
-
177
- cascade_struct = ModuleCluster::CascadeFeatures.cascade_struct_for_set_stack( self, class_or_module, cluster_stack.cascading_prepending_extends )
178
- ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
179
-
180
- super
181
-
182
- end
183
-
184
- ##############
185
- # extended #
186
- ##############
187
-
188
- def extended( class_or_module )
189
-
190
- super
191
-
192
- cascade_struct = ModuleCluster::CascadeFeatures.cascade_struct_for_set_stack( self, class_or_module, cluster_stack.cascading_extends )
193
- ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
194
-
195
- end
196
-
197
- end