module-cluster 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/lib/module-cluster.rb +17 -13
  2. data/lib/module-cluster/ModuleCluster.rb +8 -8
  3. data/lib/module-cluster/ModuleCluster/CascadeFeatures.rb +155 -0
  4. data/lib/module-cluster/ModuleCluster/ClusterStack.rb +102 -0
  5. data/lib/module-cluster/ModuleCluster/Define/Cluster.rb +203 -0
  6. data/lib/module-cluster/ModuleCluster/Define/ClusterCascades.rb +220 -0
  7. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb +209 -0
  8. data/lib/module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb +209 -0
  9. data/lib/module-cluster/ModuleCluster/Define/ClusterStack.rb +26 -0
  10. data/lib/module-cluster/ModuleCluster/Define/DedoubleAncestors.rb +22 -0
  11. data/lib/module-cluster/ModuleCluster/ExtendForCascade.rb +15 -0
  12. data/spec/ModuleCluster/Define/ClusterCascadesToClass_spec.rb +421 -0
  13. data/spec/ModuleCluster/Define/ClusterCascadesToModule_spec.rb +432 -0
  14. data/spec/ModuleCluster/Define/ClusterCascades_spec.rb +345 -0
  15. data/spec/ModuleCluster/Define/Cluster_spec.rb +275 -0
  16. data/spec/ModuleCluster_spec.rb +4 -4
  17. metadata +16 -14
  18. data/lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb +0 -211
  19. data/lib/module-cluster/ModuleCluster/Define/ModuleClusterCascades.rb +0 -223
  20. data/lib/module-cluster/ModuleCluster/Define/ModuleClusterCascadesToClass.rb +0 -223
  21. data/lib/module-cluster/ModuleCluster/Define/ModuleClusterCascadesToModule.rb +0 -227
  22. data/lib/module-cluster/ModuleCluster/Define/_private_/AnonymousModule.rb +0 -121
  23. data/lib/module-cluster/ModuleCluster/Define/_private_/ClusterStack.rb +0 -55
  24. data/spec/ModuleCluster/Define/ModuleClusterCascadesToClass_spec.rb +0 -421
  25. data/spec/ModuleCluster/Define/ModuleClusterCascadesToModule_spec.rb +0 -432
  26. data/spec/ModuleCluster/Define/ModuleClusterCascades_spec.rb +0 -345
  27. data/spec/ModuleCluster/Define/ModuleCluster_spec.rb +0 -275
  28. data/spec/ModuleCluster/Define/_private_/ClusterStack_spec.rb +0 -24
@@ -1,32 +1,36 @@
1
1
 
2
2
  module ModuleCluster
3
- module Eigenclass
3
+ class ClusterStack
4
+ end
5
+ module CascadeFeatures
4
6
  end
5
7
  module Define
6
- module AnonymousModule
8
+ module DedoubleAncestors
7
9
  end
8
10
  module ClusterStack
9
11
  end
10
- module ModuleCluster
12
+ module Cluster
11
13
  end
12
- module ModuleClusterCascades
14
+ module ClusterCascades
13
15
  end
14
- module ModuleClusterCascadesToClass
16
+ module ClusterCascadesToClass
15
17
  end
16
- module ModuleClusterCascadesToModule
18
+ module ClusterCascadesToModule
17
19
  end
18
20
  module Deprecated
19
21
  end
20
22
  end
21
23
  end
22
24
 
23
- require_relative 'module-cluster/ModuleCluster/Define/_private_/AnonymousModule.rb'
24
- require_relative 'module-cluster/ModuleCluster/Define/_private_/ClusterStack.rb'
25
-
26
- require_relative 'module-cluster/ModuleCluster/Define/ModuleCluster.rb'
27
- require_relative 'module-cluster/ModuleCluster/Define/ModuleClusterCascades.rb'
28
- require_relative 'module-cluster/ModuleCluster/Define/ModuleClusterCascadesToClass.rb'
29
- require_relative 'module-cluster/ModuleCluster/Define/ModuleClusterCascadesToModule.rb'
25
+ require_relative 'module-cluster/ModuleCluster/CascadeFeatures.rb'
26
+ require_relative 'module-cluster/ModuleCluster/Define/DedoubleAncestors.rb'
27
+ require_relative 'module-cluster/ModuleCluster/ExtendForCascade.rb'
28
+ require_relative 'module-cluster/ModuleCluster/Define/ClusterStack.rb'
29
+ require_relative 'module-cluster/ModuleCluster/Define/Cluster.rb'
30
+ require_relative 'module-cluster/ModuleCluster/Define/ClusterCascades.rb'
31
+ require_relative 'module-cluster/ModuleCluster/Define/ClusterCascadesToClass.rb'
32
+ require_relative 'module-cluster/ModuleCluster/Define/ClusterCascadesToModule.rb'
30
33
  require_relative 'module-cluster/ModuleCluster/Define/Deprecated.rb'
34
+ require_relative 'module-cluster/ModuleCluster/ClusterStack.rb'
31
35
  require_relative 'module-cluster/ModuleCluster.rb'
32
36
 
@@ -1,13 +1,13 @@
1
1
 
2
2
  module ModuleCluster
3
-
4
- include ModuleCluster::Define::ClusterStack
5
-
6
- include ModuleCluster::Define::ModuleCluster
7
- include ModuleCluster::Define::ModuleClusterCascades
8
- include ModuleCluster::Define::ModuleClusterCascadesToClass
9
- include ModuleCluster::Define::ModuleClusterCascadesToModule
3
+
4
+ extend ModuleCluster::ExtendForCascade
5
+
6
+ include ModuleCluster::Define::Cluster
7
+ include ModuleCluster::Define::ClusterCascades
8
+ include ModuleCluster::Define::ClusterCascadesToClass
9
+ include ModuleCluster::Define::ClusterCascadesToModule
10
10
 
11
11
  include ModuleCluster::Define::Deprecated
12
-
12
+
13
13
  end
@@ -0,0 +1,155 @@
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
+ return includes_or_extends
23
+
24
+ end
25
+
26
+ ############################################
27
+ # self.includes_or_extends_for_set_stack #
28
+ ############################################
29
+
30
+ def self.includes_or_extends_for_set_stack( module_self, class_or_module, set_stack )
31
+
32
+ includes = Array.new
33
+ extends = Array.new
34
+ cascades = Hash.new
35
+
36
+ set_stack.each do |this_set|
37
+
38
+ # get cascades
39
+ if this_set.dependency_module.should_cascade?( class_or_module )
40
+ cascades[ this_set.dependency_module ] ||= Hash.new
41
+ cascades[ this_set.dependency_module ][ this_set.method ] ||= Array.new
42
+ cascades[ this_set.dependency_module ][ this_set.method ].concat( this_set.modules )
43
+ end
44
+
45
+ # get runtime block
46
+ runtime_set = nil
47
+ if block = this_set.runtime_includes_or_extends_block
48
+ runtime_set = ModuleCluster::CascadeFeatures.get_runtime_includes_or_extends_from_block( module_self,
49
+ class_or_module,
50
+ this_set.include_or_extend,
51
+ block )
52
+ end
53
+
54
+ # get includes/extends
55
+ case this_set.include_or_extend
56
+ when :include
57
+ this_set.modules.each do |this_module|
58
+ if this_set.dependency_module.should_include_or_extend?( class_or_module )
59
+ includes.concat( this_set.modules )
60
+ end
61
+ end
62
+ includes.concat( runtime_set ) if runtime_set
63
+ when :extend
64
+ if this_set.dependency_module.should_include_or_extend?( class_or_module )
65
+ extends.concat( this_set.modules )
66
+ end
67
+ extends.concat( runtime_set ) if runtime_set
68
+ end
69
+
70
+ end
71
+
72
+ includes.uniq!
73
+ extends.uniq!
74
+ cascades.each do |this_dependency_module, this_method_and_module_set|
75
+ this_method_and_module_set.each do |this_method, this_module_set|
76
+ this_module_set.uniq!
77
+ end
78
+ end
79
+
80
+ return ModuleCluster::CascadeFeatures::CascadeStruct.new( includes, extends, cascades )
81
+
82
+ end
83
+
84
+ ###########################
85
+ # self.cascade_features #
86
+ ###########################
87
+
88
+ def self.cascade_features( class_or_module, cascade_struct )
89
+
90
+ class_or_module.module_eval do
91
+ include( *cascade_struct.includes.reverse ) unless cascade_struct.includes.empty?
92
+ extend( *cascade_struct.extends.reverse ) unless cascade_struct.extends.empty?
93
+ end
94
+
95
+ cascade_struct.cascades.each do |this_dependency_module, this_method_and_module_set|
96
+ this_method_and_module_set.each do |this_method, this_module_set|
97
+ this_dependency_module.perform_cascades( class_or_module, this_method, this_module_set )
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ #####################
104
+ # append_features #
105
+ #####################
106
+
107
+ def append_features( class_or_module )
108
+
109
+ cascade_struct = ModuleCluster::CascadeFeatures.includes_or_extends_for_set_stack( self, class_or_module, cluster_stack.cascading_prepending_includes )
110
+ ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
111
+
112
+ super
113
+
114
+ end
115
+
116
+ ##############
117
+ # included #
118
+ ##############
119
+
120
+ def included( class_or_module )
121
+
122
+ super
123
+
124
+ cascade_struct = ModuleCluster::CascadeFeatures.includes_or_extends_for_set_stack( self, class_or_module, cluster_stack.cascading_includes )
125
+ ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
126
+
127
+ end
128
+
129
+ ###################
130
+ # extend_object #
131
+ ###################
132
+
133
+ def extend_object( class_or_module )
134
+
135
+ cascade_struct = ModuleCluster::CascadeFeatures.includes_or_extends_for_set_stack( self, class_or_module, cluster_stack.cascading_prepending_extends )
136
+ ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
137
+
138
+ super
139
+
140
+ end
141
+
142
+ ##############
143
+ # extended #
144
+ ##############
145
+
146
+ def extended( class_or_module )
147
+
148
+ super
149
+
150
+ cascade_struct = ModuleCluster::CascadeFeatures.includes_or_extends_for_set_stack( self, class_or_module, cluster_stack.cascading_extends )
151
+ ModuleCluster::CascadeFeatures.cascade_features( class_or_module, cascade_struct )
152
+
153
+ end
154
+
155
+ end
@@ -0,0 +1,102 @@
1
+
2
+ class ModuleCluster::ClusterStack
3
+
4
+ Set = Struct.new( :dependency_module, :method, :include_or_extend, :modules, :runtime_includes_or_extends_block )
5
+
6
+ ########################
7
+ # cascading_includes #
8
+ ########################
9
+
10
+ def cascading_includes
11
+ return @cascading_includes ||= Array.new
12
+ end
13
+
14
+ #######################
15
+ # cascading_extends #
16
+ #######################
17
+
18
+ def cascading_extends
19
+ return @cascading_extends ||= Array.new
20
+ end
21
+
22
+ ###################################
23
+ # cascading_prepending_includes #
24
+ ###################################
25
+
26
+ def cascading_prepending_includes
27
+ return @cascading_prepending_includes ||= Array.new
28
+ end
29
+
30
+ ##################################
31
+ # cascading_prepending_extends #
32
+ ##################################
33
+
34
+ def cascading_prepending_extends
35
+ return @cascading_prepending_extends ||= Array.new
36
+ end
37
+
38
+ ######################
39
+ # include_includes #
40
+ ######################
41
+
42
+ def include_includes( module_instance, method, includes, runtime_includes_block )
43
+ cascading_includes.push( Set.new( module_instance, method, :include, includes, runtime_includes_block ) )
44
+ end
45
+
46
+ #####################
47
+ # include_extends #
48
+ #####################
49
+
50
+ def include_extends( module_instance, method, extends, runtime_extends_block )
51
+ cascading_includes.push( Set.new( module_instance, method, :extend, extends, runtime_extends_block ) )
52
+ end
53
+
54
+ #####################
55
+ # extend_includes #
56
+ #####################
57
+
58
+ def extend_includes( module_instance, method, includes, runtime_includes_block )
59
+ cascading_extends.push( Set.new( module_instance, method, :include, includes, runtime_includes_block ) )
60
+ end
61
+
62
+ ####################
63
+ # extend_extends #
64
+ ####################
65
+
66
+ def extend_extends( module_instance, method, extends, runtime_extends_block )
67
+ cascading_extends.push( Set.new( module_instance, method, :extend, extends, runtime_extends_block ) )
68
+ end
69
+
70
+ ###############################
71
+ # include_prepends_includes #
72
+ ###############################
73
+
74
+ def include_prepends_includes( module_instance, method, includes, runtime_includes_block )
75
+ cascading_prepending_includes.push( Set.new( module_instance, method, :include, includes, runtime_includes_block ) )
76
+ end
77
+
78
+ ##############################
79
+ # include_prepends_extends #
80
+ ##############################
81
+
82
+ def include_prepends_extends( module_instance, method, extends, runtime_extends_block )
83
+ cascading_prepending_includes.push( Set.new( module_instance, method, :extend, extends, runtime_extends_block ) )
84
+ end
85
+
86
+ ##############################
87
+ # extend_prepends_includes #
88
+ ##############################
89
+
90
+ def extend_prepends_includes( module_instance, method, includes, runtime_includes_block )
91
+ cascading_prepending_extends.push( Set.new( module_instance, method, :include, includes, runtime_includes_block ) )
92
+ end
93
+
94
+ #############################
95
+ # extend_prepends_extends #
96
+ #############################
97
+
98
+ def extend_prepends_extends( module_instance, method, extends, runtime_extends_block )
99
+ cascading_prepending_extends.push( Set.new( module_instance, method, :extend, extends, runtime_extends_block ) )
100
+ end
101
+
102
+ end
@@ -0,0 +1,203 @@
1
+
2
+ module ModuleCluster::Define::Cluster
3
+
4
+ include ModuleCluster::Define::ClusterStack
5
+
6
+ extend ModuleCluster::ExtendForCascade
7
+
8
+ ####################################
9
+ # self.should_include_or_extend? #
10
+ ####################################
11
+
12
+ def self.should_include_or_extend?( class_or_module )
13
+ return true
14
+ end
15
+
16
+ ##########################
17
+ # self.should_cascade? #
18
+ ##########################
19
+
20
+ def self.should_cascade?( class_or_module )
21
+ return true
22
+ end
23
+
24
+ ###########################
25
+ # self.perform_cascades #
26
+ ###########################
27
+
28
+ def self.perform_cascades( class_or_module, method, modules )
29
+ end
30
+
31
+ ###########################
32
+ # include_also_includes #
33
+ ###########################
34
+
35
+ def include_also_includes( *includes, & runtime_includes_block )
36
+ cluster_stack.include_includes( ModuleCluster::Define::Cluster, __method__, includes, runtime_includes_block )
37
+ return self
38
+ end
39
+
40
+ ##########################
41
+ # include_also_extends #
42
+ ##########################
43
+
44
+ def include_also_extends( *extends, & runtime_extends_block )
45
+ cluster_stack.include_extends( ModuleCluster::Define::Cluster, __method__, extends, runtime_extends_block )
46
+ return self
47
+ end
48
+
49
+ #######################################
50
+ # include_also_includes_and_extends #
51
+ #######################################
52
+
53
+ def include_also_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
54
+ include_also_includes( *includes_and_extends, & runtime_includes_and_extends_block )
55
+ include_also_extends( *includes_and_extends, & runtime_includes_and_extends_block )
56
+ return self
57
+ end
58
+
59
+ ##########################
60
+ # extend_also_includes #
61
+ ##########################
62
+
63
+ def extend_also_includes( *includes, & runtime_includes_block )
64
+ cluster_stack.extend_includes( ModuleCluster::Define::Cluster, __method__, includes, runtime_includes_block )
65
+ return self
66
+ end
67
+
68
+ #########################
69
+ # extend_also_extends #
70
+ #########################
71
+
72
+ def extend_also_extends( *extends, & runtime_extends_block )
73
+ cluster_stack.extend_extends( ModuleCluster::Define::Cluster, __method__, extends, runtime_extends_block )
74
+ return self
75
+ end
76
+
77
+ ######################################
78
+ # extend_also_includes_and_extends #
79
+ ######################################
80
+
81
+ def extend_also_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
82
+ extend_also_includes( *includes_and_extends, & runtime_includes_and_extends_block )
83
+ extend_also_extends( *includes_and_extends, & runtime_includes_and_extends_block )
84
+ return self
85
+ end
86
+
87
+ ###############################
88
+ # include_prepends_includes #
89
+ ###############################
90
+
91
+ def include_prepends_includes( *includes, & runtime_includes_block )
92
+ cluster_stack.include_prepends_includes( ModuleCluster::Define::Cluster, __method__, includes, runtime_includes_block )
93
+ return self
94
+ end
95
+
96
+ ##############################
97
+ # include_prepends_extends #
98
+ ##############################
99
+
100
+ def include_prepends_extends( *extends, & runtime_extends_block )
101
+ cluster_stack.include_prepends_extends( ModuleCluster::Define::Cluster, __method__, extends, runtime_extends_block )
102
+ return self
103
+ end
104
+
105
+ ###########################################
106
+ # include_prepends_includes_and_extends #
107
+ ###########################################
108
+
109
+ def include_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
110
+ include_prepends_includes( *includes_and_extends, & runtime_includes_and_extends_block )
111
+ include_prepends_extends( *includes_and_extends, & runtime_includes_and_extends_block )
112
+ return self
113
+ end
114
+
115
+ ##############################
116
+ # extend_prepends_includes #
117
+ ##############################
118
+
119
+ def extend_prepends_includes( *includes, & runtime_includes_block )
120
+ cluster_stack.extend_prepends_includes( ModuleCluster::Define::Cluster, __method__, includes, runtime_includes_block )
121
+ return self
122
+ end
123
+
124
+ #############################
125
+ # extend_prepends_extends #
126
+ #############################
127
+
128
+ def extend_prepends_extends( *extends, & runtime_extends_block )
129
+ cluster_stack.extend_prepends_extends( ModuleCluster::Define::Cluster, __method__, extends, runtime_extends_block )
130
+ return self
131
+ end
132
+
133
+ ##########################################
134
+ # extend_prepends_includes_and_extends #
135
+ ##########################################
136
+
137
+ def extend_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
138
+ extend_prepends_includes( *includes_and_extends, & runtime_includes_and_extends_block )
139
+ extend_prepends_extends( *includes_and_extends, & runtime_includes_and_extends_block )
140
+ return self
141
+ end
142
+
143
+ #####################################
144
+ # include_or_extend_also_includes #
145
+ #####################################
146
+
147
+ def include_or_extend_also_includes( *includes, & runtime_includes_block )
148
+ include_also_includes( *includes, & runtime_includes_block )
149
+ extend_also_includes( *includes, & runtime_includes_block )
150
+ return self
151
+ end
152
+
153
+ ####################################
154
+ # include_or_extend_also_extends #
155
+ ####################################
156
+
157
+ def include_or_extend_also_extends( *extends, & runtime_extends_block )
158
+ include_also_extends( *extends, & runtime_extends_block )
159
+ extend_also_extends( *extends, & runtime_extends_block )
160
+ return self
161
+ end
162
+
163
+ #################################################
164
+ # include_or_extend_also_includes_and_extends #
165
+ #################################################
166
+
167
+ def include_or_extend_also_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
168
+ include_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
169
+ extend_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
170
+ return self
171
+ end
172
+
173
+ #########################################
174
+ # include_or_extend_prepends_includes #
175
+ #########################################
176
+
177
+ def include_or_extend_prepends_includes( *includes, & runtime_includes_block )
178
+ include_prepends_includes( *includes, & runtime_includes_block )
179
+ extend_prepends_includes( *includes, & runtime_includes_block )
180
+ return self
181
+ end
182
+
183
+ ########################################
184
+ # include_or_extend_prepends_extends #
185
+ ########################################
186
+
187
+ def include_or_extend_prepends_extends( *extends, & runtime_extends_block )
188
+ include_prepends_extends( *extends, & runtime_extends_block )
189
+ extend_prepends_extends( *extends, & runtime_extends_block )
190
+ return self
191
+ end
192
+
193
+ #####################################################
194
+ # include_or_extend_prepends_includes_and_extends #
195
+ #####################################################
196
+
197
+ def include_or_extend_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
198
+ include_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
199
+ extend_prepends_includes_and_extends( *includes_and_extends, & runtime_includes_and_extends_block )
200
+ return self
201
+ end
202
+
203
+ end