module-cluster 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/README.md +54 -156
  2. data/README.rdoc +54 -130
  3. data/lib/module-cluster.rb +20 -16
  4. data/lib/module-cluster/ModuleCluster.rb +4 -120
  5. data/lib/module-cluster/ModuleCluster/Define/Deprecated.rb +40 -0
  6. data/lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb +140 -0
  7. data/lib/module-cluster/ModuleCluster/Define/ModuleClusterCascades.rb +140 -0
  8. data/lib/module-cluster/ModuleCluster/Define/ModuleClusterCascadesToClass.rb +140 -0
  9. data/lib/module-cluster/ModuleCluster/Define/_private_/ClusterStack.rb +28 -0
  10. data/lib/module-cluster/ModuleCluster/Define/_private_/ModuleCluster.rb +110 -0
  11. data/lib/module-cluster/ModuleCluster/Define/_private_/ModuleClusterCascades.rb +118 -0
  12. data/lib/module-cluster/ModuleCluster/Define/_private_/ModuleClusterCascadesToClass.rb +126 -0
  13. data/spec/ModuleCluster/Define/ModuleClusterCascadesToClass_spec.rb +421 -0
  14. data/spec/ModuleCluster/Define/ModuleClusterCascades_spec.rb +345 -0
  15. data/spec/ModuleCluster/Define/ModuleCluster_spec.rb +275 -0
  16. data/spec/ModuleCluster/Define/_private_/ClusterStack_spec.rb +24 -0
  17. data/spec/ModuleCluster/Define/_private_/ModuleClusterCascadesToClass_spec.rb +249 -0
  18. data/spec/ModuleCluster/Define/_private_/ModuleClusterCascades_spec.rb +223 -0
  19. data/spec/ModuleCluster/Define/_private_/ModuleCluster_spec.rb +168 -0
  20. data/spec/ModuleCluster_spec.rb +7 -2549
  21. metadata +21 -12
  22. data/lib/module-cluster/ModuleCluster/ExtendSupport.rb +0 -95
  23. data/lib/module-cluster/ModuleCluster/IncludeExtendSupport.rb +0 -104
  24. data/lib/module-cluster/ModuleCluster/IncludeSupport.rb +0 -94
  25. data/lib/module-cluster/ModuleCluster/_private_/IncludeExtendSupport.rb +0 -56
  26. data/lib/module-cluster/_private_/ModuleCluster.rb +0 -23
  27. data/spec/ModuleCluster/IncludeExtendSupport_spec.rb +0 -46
data/README.md CHANGED
@@ -4,21 +4,11 @@ http://rubygems.org/gems/module-cluster
4
4
 
5
5
  # Description #
6
6
 
7
- Adds methods for defining module clusters using #included and #extended.
7
+ Adds methods for defining module clusters using #included, #extended, #append_features, and #extend_object.
8
8
 
9
9
  # Summary #
10
10
 
11
- Provides:
12
-
13
- * :define_module_included
14
- * :define_module_extended
15
- * :define_module_cluster
16
- * :define_module_included_cascades
17
- * :define_module_extended_cascades
18
- * :define_module_cluster_cascades
19
- * :define_module_included_cascades_to_class
20
- * :define_module_extended_cascades_to_class
21
- * :define_module_cluster_cascades_to_class
11
+ 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
12
 
23
13
  # Install #
24
14
 
@@ -34,157 +24,65 @@ module SomeModule
34
24
  end
35
25
  ```
36
26
 
37
- ## The Basic Idea ##
38
-
39
- We use blocks to define cascading module includes/extends. This automates calls to super (so we don't forget) and puts self.included/self.extended support into a module so that local overriding is still possible.
40
-
41
- The block provides arrays to hold includes/extends. If two arrays [ includes, extends ] are returned by the block, they will be used. Otherwise the arrays passed in by parameters will be used. This means, due to how Ruby handles references, that *if you set one of the parameter arrays to a new array you have to return both arrays* or your changes won't be added.
42
-
43
- Calls to define_module_... functions are cumulative, permitting multiple calls (whether subsequently or otherwise). This is particularly useful for configuring including/extending modules from the included/extended module (and so on - nested blocks permit this sort of determination indefinitely).
44
-
45
- ## define_module_included ##
46
-
47
- To cause modules to be included when this module is included:
48
-
49
- ```ruby
50
- module SomeModule
51
- define_module_included do |includes, extends|
52
- includes.concat [ SomeOtherModule ]
53
- end
54
- end
55
- ```
56
-
57
- or extended when this module is included:
58
-
59
- ```ruby
60
- module SomeModule
61
- define_module_included do |includes, extends|
62
- extends.concat [ SomeOtherModule ]
63
- end
64
- end
65
- ```
66
-
67
- ## define_module_extended ##
68
-
69
- To cause modules to be included when this module is extended:
70
-
71
- ```ruby
72
- module SomeModule
73
- define_module_extended do |includes, extends|
74
- includes.concat [ SomeOtherModule ]
75
- end
76
- end
77
- ```
78
-
79
- or extended when this module is extended:
80
-
81
- ```ruby
82
- module SomeModule
83
- define_module_extended do |includes, extends|
84
- extends.concat [ SomeOtherModule ]
85
- end
86
- end
87
- ```
88
-
89
- ## define_module_cluster ##
90
-
91
- To cause modules to be included when this module is included or extended:
92
-
93
- ```ruby
94
- module SomeModule
95
- define_module_cluster do |includes, extends|
96
- includes.concat [ SomeOtherModule ]
97
- end
98
- end
99
- ```
27
+ Definition methods accept modules as arguments.
100
28
 
101
- or extended when this module is included or extended:
29
+ For example:
102
30
 
103
31
  ```ruby
104
32
  module SomeModule
105
- define_module_cluster do |includes, extends|
106
- extends.concat [ SomeOtherModule ]
107
- end
108
- end
109
- ```
110
-
111
- ## define_module_included_cascades ##
112
-
113
- To cause modules to be included or extended when this module is used to include in a class or module.
114
-
115
- ```ruby
116
- module SomeModule
117
- define_module_included_cascades do |includes, extends|
118
- includes.concat [ SomeOtherModule ]
119
- extends.concat [ SomeOtherModule ]
120
- end
121
- end
122
- ```
123
-
124
- ## define_module_extended_cascades ##
125
-
126
- To cause modules to be included or extended when this module is used to extend in a class or module:
127
-
128
- ```ruby
129
- module SomeModule
130
- define_module_extended_cascades do |includes, extends|
131
- includes.concat [ SomeOtherModule ]
132
- extends.concat [ SomeOtherModule ]
133
- end
134
- end
135
- ```
136
-
137
- ## define_module_cluster_cascades ##
138
-
139
- To cause modules to be included or extended when this module is used to include or extend in a class or module:
140
-
141
- ```ruby
142
- module SomeModule
143
- define_module_cluster_cascades do |includes, extends|
144
- includes.concat [ SomeOtherModule ]
145
- extends.concat [ SomeOtherModule ]
146
- end
147
- end
148
- ```
149
-
150
- ## define_module_included_cascades_to_class ##
151
-
152
- To cause modules to be included or extended when this module is used to include in a class (and not a module):
153
-
154
- ```ruby
155
- module SomeModule
156
- define_module_included_cascades_to_class do |includes, extends|
157
- includes.concat [ SomeOtherModule ]
158
- extends.concat [ SomeOtherModule ]
159
- end
160
- end
161
- ```
162
-
163
- ## define_module_extended_cascades_to_class ##
164
-
165
- To cause modules to be included or extended when this module is used to extend in a class (and not a module):
166
-
167
- ```ruby
168
- module SomeModule
169
- define_module_extended_cascades_to_class do |includes, extends|
170
- includes.concat [ SomeOtherModule ]
171
- extends.concat [ SomeOtherModule ]
172
- end
33
+ include ModuleCluster
34
+ include_also_includes( SomeOtherModule )
173
35
  end
174
36
  ```
175
37
 
176
- ## define_module_cluster_cascades_to_class ##
177
-
178
- To cause modules to be included or extended when this module is used to include or extend in a class (and not a module):
179
-
180
- ```ruby
181
- module SomeModule
182
- define_module_cluster_cascades_to_class do |includes, extends|
183
- includes.concat [ SomeOtherModule ]
184
- extends.concat [ SomeOtherModule ]
185
- end
186
- end
187
- ```
38
+ Calls to the various functions are cumulative and stack in the order called. This permits multiple calls, whether subsequently or otherwise.
39
+
40
+ # Methods #
41
+
42
+ Cluster methods:
43
+
44
+ * include_also_includes
45
+ * include_also_extends
46
+ * include_also_includes_and_extends
47
+ * extend_also_includes
48
+ * extend_also_extends
49
+ * extend_also_includes_and_extends
50
+ * include_prepends_includes
51
+ * include_prepends_extends
52
+ * include_prepends_includes_and_extends
53
+ * extend_prepends_includes
54
+ * extend_prepends_extends
55
+ * extend_prepends_includes_and_extends
56
+
57
+ Cascade methods:
58
+
59
+ * include_cascades_includes
60
+ * include_cascades_extends
61
+ * include_cascades_includes_and_extends
62
+ * extend_cascades_includes
63
+ * extend_cascades_extends
64
+ * extend_cascades_includes_and_extends
65
+ * include_cascades_prepending_includes
66
+ * include_cascades_prepending_extends
67
+ * include_cascades_prepending_includes_and_extends
68
+ * extend_cascades_prepending_includes
69
+ * extend_cascades_prepending_extends
70
+ * extend_cascades_prepending_includes_and_extends
71
+
72
+ Cascade to class methods:
73
+
74
+ * include_cascades_includes_to_class
75
+ * include_cascades_extends_to_class
76
+ * include_cascades_includes_and_extends_to_class
77
+ * extend_cascades_includes_to_class
78
+ * extend_cascades_extends_to_class
79
+ * extend_cascades_includes_and_extends_to_class
80
+ * include_cascades_to_class_prepending_includes
81
+ * include_cascades_to_class_prepending_extends
82
+ * include_cascades_to_class_prepending_includes_and_extends
83
+ * extend_cascades_to_class_prepending_includes
84
+ * extend_cascades_to_class_prepending_extends
85
+ * extend_cascades_to_class_prepending_includes_and_extends
188
86
 
189
87
  # License #
190
88
 
@@ -4,17 +4,11 @@ http://rubygems.org/gems/module-cluster
4
4
 
5
5
  == Description
6
6
 
7
- Adds methods for defining module clusters using #included and #extended.
7
+ Adds methods for defining module clusters using #included, #extended, #append_features, and #extend_object.
8
8
 
9
9
  == Summary
10
10
 
11
- Provides:
12
- * :define_module_included
13
- * :define_module_extended
14
- * :define_module_cluster
15
- * :define_module_included_cascades_to_class
16
- * :define_module_extended_cascades_to_class
17
- * :define_module_cluster_cascades_to_class
11
+ 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).
18
12
 
19
13
  == Install
20
14
 
@@ -28,133 +22,63 @@ module SomeModule
28
22
  include ModuleCluster
29
23
  end
30
24
 
31
- === The Basic Idea
25
+ Definition methods accept modules as arguments.
32
26
 
33
- We use blocks to define cascading module includes/extends. This automates calls to super (so we don't forget) and puts self.included/self.extended support into a module so that local overriding is still possible.
34
-
35
- The block provides arrays with the current set of includes/extends to cascade for the module. If two arrays [ includes, extends ] are returned by the block, they will be used. Otherwise the arrays passed in by parameters will be used. This means, due to how Ruby handles references, that *if you set one of the parameter arrays to a new array you have to return both arrays* or your changes won't be added.
36
-
37
- Calls to define_module_... functions are cumulative, permitting multiple calls (whether subsequently or otherwise). This is particularly useful for configuring including/extending modules from the included/extended module (and so on - nested blocks permit this sort of determination indefinitely).
38
-
39
- === define_module_included
40
-
41
- To cause modules to be included when this module is included:
42
-
43
- module SomeModule
44
- define_module_included do |includes, extends|
45
- includes.concat [ SomeOtherModule ]
46
- end
47
- end
48
-
49
- or extended when this module is included:
50
-
51
- module SomeModule
52
- define_module_included do |includes, extends|
53
- extends.concat [ SomeOtherModule ]
54
- end
55
- end
56
-
57
- === define_module_extended
58
-
59
- To cause modules to be included when this module is extended:
60
-
61
- module SomeModule
62
- define_module_extended do |includes, extends|
63
- includes.concat [ SomeOtherModule ]
64
- end
65
- end
66
-
67
- or extended when this module is extended:
68
-
69
- module SomeModule
70
- define_module_extended do |includes, extends|
71
- extends.concat [ SomeOtherModule ]
72
- end
73
- end
74
-
75
- === define_module_cluster
76
-
77
- To cause modules to be included when this module is included or extended:
78
-
79
- module SomeModule
80
- define_module_cluster do |includes, extends|
81
- includes.concat [ SomeOtherModule ]
82
- end
83
- end
84
-
85
- or extended when this module is included or extended:
86
-
87
- module SomeModule
88
- define_module_cluster do |includes, extends|
89
- extends.concat [ SomeOtherModule ]
90
- end
91
- end
92
-
93
- === define_module_included_cascades
94
-
95
- To cause modules to be included or extended when this module is used to include in a class or module.
96
-
97
- module SomeModule
98
- define_module_included_cascades do |includes, extends|
99
- includes.concat [ SomeOtherModule ]
100
- extends.concat [ SomeOtherModule ]
101
- end
102
- end
103
-
104
- === define_module_extended_cascades
105
-
106
- To cause modules to be included or extended when this module is used to extend in a class or module:
107
-
108
- module SomeModule
109
- define_module_extended_cascades do |includes, extends|
110
- includes.concat [ SomeOtherModule ]
111
- extends.concat [ SomeOtherModule ]
112
- end
113
- end
114
-
115
- === define_module_cluster_cascades
116
-
117
- To cause modules to be included or extended when this module is used to include or extend in a class or module:
118
-
119
- module SomeModule
120
- define_module_cluster_cascades do |includes, extends|
121
- includes.concat [ SomeOtherModule ]
122
- extends.concat [ SomeOtherModule ]
123
- end
124
- end
125
-
126
- === define_module_included_cascades_to_class
127
-
128
- To cause modules to be included or extended when this module is used to include a class (and not a module):
129
-
130
- module SomeModule
131
- define_module_included_cascades_to_class do |includes, extends|
132
- includes.concat [ SomeOtherModule ]
133
- extends.concat [ SomeOtherModule ]
134
- end
135
- end
136
-
137
- === define_module_extended_cascades_to_class
138
-
139
- To cause modules to be included or extended when this module is used to extend a class (and not a module):
27
+ For example:
140
28
 
141
29
  module SomeModule
142
- define_module_extended_cascades_to_class do |includes, extends|
143
- includes.concat [ SomeOtherModule ]
144
- extends.concat [ SomeOtherModule ]
145
- end
30
+ include ModuleCluster
31
+ include_also_includes( SomeOtherModule )
146
32
  end
147
33
 
148
- === define_module_cluster_cascades_to_class
149
-
150
- To cause modules to be included or extended when this module is used to include or extend a class (and not a module):
151
-
152
- module SomeModule
153
- define_module_cluster_cascades_to_class do |includes, extends|
154
- includes.concat [ SomeOtherModule ]
155
- extends.concat [ SomeOtherModule ]
156
- end
157
- end
34
+ Calls to the various functions are cumulative and stack in the order called. This permits multiple calls, whether subsequently or otherwise.
35
+
36
+ == Methods
37
+
38
+ Cluster methods:
39
+
40
+ * include_also_includes
41
+ * include_also_extends
42
+ * include_also_includes_and_extends
43
+ * extend_also_includes
44
+ * extend_also_extends
45
+ * extend_also_includes_and_extends
46
+ * include_prepends_includes
47
+ * include_prepends_extends
48
+ * include_prepends_includes_and_extends
49
+ * extend_prepends_includes
50
+ * extend_prepends_extends
51
+ * extend_prepends_includes_and_extends
52
+
53
+ Cascade methods:
54
+
55
+ * include_cascades_includes
56
+ * include_cascades_extends
57
+ * include_cascades_includes_and_extends
58
+ * extend_cascades_includes
59
+ * extend_cascades_extends
60
+ * extend_cascades_includes_and_extends
61
+ * include_cascades_prepending_includes
62
+ * include_cascades_prepending_extends
63
+ * include_cascades_prepending_includes_and_extends
64
+ * extend_cascades_prepending_includes
65
+ * extend_cascades_prepending_extends
66
+ * extend_cascades_prepending_includes_and_extends
67
+
68
+ Cascade to class methods:
69
+
70
+ * include_cascades_includes_to_class
71
+ * include_cascades_extends_to_class
72
+ * include_cascades_includes_and_extends_to_class
73
+ * extend_cascades_includes_to_class
74
+ * extend_cascades_extends_to_class
75
+ * extend_cascades_includes_and_extends_to_class
76
+ * include_cascades_to_class_prepending_includes
77
+ * include_cascades_to_class_prepending_extends
78
+ * include_cascades_to_class_prepending_includes_and_extends
79
+ * extend_cascades_to_class_prepending_includes
80
+ * extend_cascades_to_class_prepending_extends
81
+ * extend_cascades_to_class_prepending_includes_and_extends
158
82
 
159
83
  == License
160
84
 
@@ -1,21 +1,25 @@
1
1
 
2
2
  module ModuleCluster
3
- module IncludeSupport
4
- end
5
- module ExtendSupport
6
- end
7
- end
8
-
9
- class Array::ClassOrModule < Array
10
- end
11
- class Array::CascadeToClass < Array
12
- end
13
- class Array::CascadeToClassOrModule < Array
3
+ module Define
4
+ module ClusterStack
5
+ end
6
+ module ModuleCluster
7
+ end
8
+ module ModuleClusterCascades
9
+ end
10
+ module ModuleClusterCascadesToClass
11
+ end
12
+ module Deprecated
13
+ end
14
+ end
14
15
  end
15
16
 
16
17
  require_relative 'module-cluster/ModuleCluster.rb'
17
- require_relative 'module-cluster/_private_/ModuleCluster.rb'
18
- require_relative 'module-cluster/ModuleCluster/IncludeExtendSupport.rb'
19
- require_relative 'module-cluster/ModuleCluster/_private_/IncludeExtendSupport.rb'
20
- require_relative 'module-cluster/ModuleCluster/IncludeSupport.rb'
21
- require_relative 'module-cluster/ModuleCluster/ExtendSupport.rb'
18
+ require_relative 'module-cluster/ModuleCluster/Define/ModuleCluster.rb'
19
+ require_relative 'module-cluster/ModuleCluster/Define/ModuleClusterCascades.rb'
20
+ require_relative 'module-cluster/ModuleCluster/Define/ModuleClusterCascadesToClass.rb'
21
+ require_relative 'module-cluster/ModuleCluster/Define/Deprecated.rb'
22
+ require_relative 'module-cluster/ModuleCluster/Define/_private_/ClusterStack.rb'
23
+ require_relative 'module-cluster/ModuleCluster/Define/_private_/ModuleCluster.rb'
24
+ require_relative 'module-cluster/ModuleCluster/Define/_private_/ModuleClusterCascades.rb'
25
+ require_relative 'module-cluster/ModuleCluster/Define/_private_/ModuleClusterCascadesToClass.rb'