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
@@ -0,0 +1,140 @@
1
+
2
+ module ModuleCluster::Define::ModuleClusterCascadesToClass
3
+
4
+ ########################################
5
+ # include_cascades_includes_to_class #
6
+ ########################################
7
+
8
+ def include_cascades_includes_to_class( *includes )
9
+ includes_module = anonymous_module_cascade_to_class_included( :include, *includes )
10
+ clusterstack_module do
11
+ include( includes_module )
12
+ end
13
+ return self
14
+ end
15
+
16
+ #######################################
17
+ # include_cascades_extends_to_class #
18
+ #######################################
19
+
20
+ def include_cascades_extends_to_class( *extends )
21
+ extends_module = anonymous_module_cascade_to_class_included( :extend, *extends )
22
+ clusterstack_module do
23
+ include( extends_module )
24
+ end
25
+ return self
26
+ end
27
+
28
+ ####################################################
29
+ # include_cascades_includes_and_extends_to_class #
30
+ ####################################################
31
+
32
+ def include_cascades_includes_and_extends_to_class( *includes_and_extends )
33
+ include_cascades_includes_to_class( *includes_and_extends )
34
+ include_cascades_extends_to_class( *includes_and_extends )
35
+ return self
36
+ end
37
+
38
+ #######################################
39
+ # extend_cascades_includes_to_class #
40
+ #######################################
41
+
42
+ def extend_cascades_includes_to_class( *includes )
43
+ includes_module = anonymous_module_cascade_to_class_extended( :include, *includes )
44
+ clusterstack_module do
45
+ include( includes_module )
46
+ end
47
+ return self
48
+ end
49
+
50
+ ######################################
51
+ # extend_cascades_extends_to_class #
52
+ ######################################
53
+
54
+ def extend_cascades_extends_to_class( *extends )
55
+ extends_module = anonymous_module_cascade_to_class_extended( :extend, *extends )
56
+ clusterstack_module do
57
+ include( extends_module )
58
+ end
59
+ return self
60
+ end
61
+
62
+ ###################################################
63
+ # extend_cascades_includes_and_extends_to_class #
64
+ ###################################################
65
+
66
+ def extend_cascades_includes_and_extends_to_class( *includes_and_extends )
67
+ extend_cascades_includes_to_class( *includes_and_extends )
68
+ extend_cascades_extends_to_class( *includes_and_extends )
69
+ return self
70
+ end
71
+
72
+ ###################################################
73
+ # include_cascades_to_class_prepending_includes #
74
+ ###################################################
75
+
76
+ def include_cascades_to_class_prepending_includes( *includes )
77
+ includes_module = anonymous_module_cascade_to_class_append_features( :include, *includes )
78
+ clusterstack_module do
79
+ include( includes_module )
80
+ end
81
+ return self
82
+ end
83
+
84
+ ##################################################
85
+ # include_cascades_to_class_prepending_extends #
86
+ ##################################################
87
+
88
+ def include_cascades_to_class_prepending_extends( *extends )
89
+ extends_module = anonymous_module_cascade_to_class_append_features( :extend, *extends )
90
+ clusterstack_module do
91
+ include( extends_module )
92
+ end
93
+ return self
94
+ end
95
+
96
+ ###############################################################
97
+ # include_cascades_to_class_prepending_includes_and_extends #
98
+ ###############################################################
99
+
100
+ def include_cascades_to_class_prepending_includes_and_extends( *includes_and_extends )
101
+ include_cascades_to_class_prepending_includes( *includes_and_extends )
102
+ include_cascades_to_class_prepending_extends( *includes_and_extends )
103
+ return self
104
+ end
105
+
106
+ ##################################################
107
+ # extend_cascades_to_class_prepending_includes #
108
+ ##################################################
109
+
110
+ def extend_cascades_to_class_prepending_includes( *includes )
111
+ includes_module = anonymous_module_cascade_to_class_extend_object( :include, *includes )
112
+ clusterstack_module do
113
+ include( includes_module )
114
+ end
115
+ return self
116
+ end
117
+
118
+ #################################################
119
+ # extend_cascades_to_class_prepending_extends #
120
+ #################################################
121
+
122
+ def extend_cascades_to_class_prepending_extends( *extends )
123
+ extends_module = anonymous_module_cascade_to_class_extend_object( :extend, *extends )
124
+ clusterstack_module do
125
+ include( extends_module )
126
+ end
127
+ return self
128
+ end
129
+
130
+ ##############################################################
131
+ # extend_cascades_to_class_prepending_includes_and_extends #
132
+ ##############################################################
133
+
134
+ def extend_cascades_to_class_prepending_includes_and_extends( *includes_and_extends )
135
+ extend_cascades_to_class_prepending_includes( *includes_and_extends )
136
+ extend_cascades_to_class_prepending_extends( *includes_and_extends )
137
+ return self
138
+ end
139
+
140
+ end
@@ -0,0 +1,28 @@
1
+
2
+ module ModuleCluster::Define::ClusterStack
3
+
4
+ ###########################################################################################################
5
+ private ###############################################################################################
6
+ ###########################################################################################################
7
+
8
+ #########################
9
+ # clusterstack_module #
10
+ #########################
11
+
12
+ def clusterstack_module( & clusterstack_extend_include_block )
13
+
14
+ unless const_defined?( :ClusterStackModule )
15
+ const_set( :ClusterStackModule, Module.new )
16
+ end
17
+
18
+ # we use a block so that we don't have to worry about re-extending each time
19
+ self::ClusterStackModule.module_eval( & clusterstack_extend_include_block ) if block_given?
20
+
21
+ # we have to re-extend each time so that new includes/extends apply to self
22
+ extend( self::ClusterStackModule )
23
+
24
+ return self::ClusterStackModule
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,110 @@
1
+
2
+ module ModuleCluster::Define::ModuleCluster
3
+
4
+ ###########################################################################################################
5
+ private ###############################################################################################
6
+ ###########################################################################################################
7
+
8
+ include ModuleCluster::Define::ClusterStack
9
+
10
+ ######################################
11
+ # anonymous_module_append_features #
12
+ ######################################
13
+
14
+ def anonymous_module_append_features( extend_or_include, *other_modules )
15
+
16
+ return Module.new do
17
+
18
+ #-------------------#
19
+ # append_features #
20
+ #-------------------#
21
+
22
+ define_method( :append_features ) do |class_or_module|
23
+ class_or_module.module_eval do
24
+ other_modules.each do |this_module|
25
+ __send__( extend_or_include, this_module )
26
+ end
27
+ end
28
+ super( class_or_module )
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ ###############################
36
+ # anonymous_module_included #
37
+ ###############################
38
+
39
+ def anonymous_module_included( extend_or_include, *other_modules )
40
+
41
+ return Module.new do
42
+
43
+ #------------#
44
+ # included #
45
+ #------------#
46
+
47
+ define_method( :included ) do |class_or_module|
48
+ super( class_or_module )
49
+ class_or_module.module_eval do
50
+ other_modules.each do |this_module|
51
+ __send__( extend_or_include, this_module )
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ ####################################
61
+ # anonymous_module_extend_object #
62
+ ####################################
63
+
64
+ def anonymous_module_extend_object( extend_or_include, *other_modules )
65
+
66
+ return Module.new do
67
+
68
+ #-----------------#
69
+ # extend_object #
70
+ #-----------------#
71
+
72
+ define_method( :extend_object ) do |class_or_module|
73
+ class_or_module.module_eval do
74
+ other_modules.each do |this_module|
75
+ __send__( extend_or_include, this_module )
76
+ end
77
+ end
78
+ super( class_or_module )
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+ ###############################
86
+ # anonymous_module_extended #
87
+ ###############################
88
+
89
+ def anonymous_module_extended( extend_or_include, *other_modules )
90
+
91
+ return Module.new do
92
+
93
+ #------------#
94
+ # included #
95
+ #------------#
96
+
97
+ define_method( :extended ) do |class_or_module|
98
+ super( class_or_module )
99
+ class_or_module.module_eval do
100
+ other_modules.each do |this_module|
101
+ __send__( extend_or_include, this_module )
102
+ end
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+
110
+ end
@@ -0,0 +1,118 @@
1
+
2
+ module ModuleCluster::Define::ModuleClusterCascades
3
+
4
+ ###########################################################################################################
5
+ private ###############################################################################################
6
+ ###########################################################################################################
7
+
8
+ include ModuleCluster::Define::ClusterStack
9
+
10
+ ##############################################
11
+ # anonymous_module_cascade_append_features #
12
+ ##############################################
13
+
14
+ def anonymous_module_cascade_append_features( extend_or_include, *other_modules )
15
+
16
+ return Module.new do
17
+
18
+ #-------------------#
19
+ # append_features #
20
+ #-------------------#
21
+
22
+ define_method( :append_features ) do |class_or_module|
23
+ class_or_module.module_eval do
24
+ extend ModuleCluster::Define::ModuleClusterCascades
25
+ extend( anonymous_module_cascade_append_features( extend_or_include, *other_modules ) )
26
+ other_modules.each do |this_module|
27
+ __send__( extend_or_include, this_module )
28
+ end
29
+ end
30
+ super( class_or_module )
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ #######################################
38
+ # anonymous_module_cascade_included #
39
+ #######################################
40
+
41
+ def anonymous_module_cascade_included( extend_or_include, *other_modules )
42
+
43
+ return Module.new do
44
+
45
+ #------------#
46
+ # included #
47
+ #------------#
48
+
49
+ define_method( :included ) do |class_or_module|
50
+ super( class_or_module )
51
+ class_or_module.module_eval do
52
+ extend ModuleCluster::Define::ModuleClusterCascades
53
+ extend( anonymous_module_cascade_included( extend_or_include, *other_modules ) )
54
+ other_modules.each do |this_module|
55
+ __send__( extend_or_include, this_module )
56
+ end
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ ############################################
65
+ # anonymous_module_cascade_extend_object #
66
+ ############################################
67
+
68
+ def anonymous_module_cascade_extend_object( extend_or_include, *other_modules )
69
+
70
+ return Module.new do
71
+
72
+ #-----------------#
73
+ # extend_object #
74
+ #-----------------#
75
+
76
+ define_method( :extend_object ) do |class_or_module|
77
+ class_or_module.module_eval do
78
+ extend ModuleCluster::Define::ModuleClusterCascades
79
+ extend( anonymous_module_cascade_extend_object( extend_or_include, *other_modules ) )
80
+ other_modules.each do |this_module|
81
+ __send__( extend_or_include, this_module )
82
+ end
83
+ end
84
+ super( class_or_module )
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ #######################################
92
+ # anonymous_module_cascade_extended #
93
+ #######################################
94
+
95
+ def anonymous_module_cascade_extended( extend_or_include, *other_modules )
96
+
97
+ return Module.new do
98
+
99
+ #------------#
100
+ # included #
101
+ #------------#
102
+
103
+ define_method( :extended ) do |class_or_module|
104
+ super( class_or_module )
105
+ class_or_module.module_eval do
106
+ extend ModuleCluster::Define::ModuleClusterCascades
107
+ extend( anonymous_module_cascade_extended( extend_or_include, *other_modules ) )
108
+ other_modules.each do |this_module|
109
+ __send__( extend_or_include, this_module )
110
+ end
111
+ end
112
+ end
113
+
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,126 @@
1
+
2
+ module ModuleCluster::Define::ModuleClusterCascadesToClass
3
+
4
+ ###########################################################################################################
5
+ private ###############################################################################################
6
+ ###########################################################################################################
7
+
8
+ include ModuleCluster::Define::ClusterStack
9
+
10
+ #######################################################
11
+ # anonymous_module_cascade_to_class_append_features #
12
+ #######################################################
13
+
14
+ def anonymous_module_cascade_to_class_append_features( extend_or_include, *other_modules )
15
+
16
+ return Module.new do
17
+
18
+ #-------------------#
19
+ # append_features #
20
+ #-------------------#
21
+
22
+ define_method( :append_features ) do |class_or_module|
23
+ class_or_module.module_eval do
24
+ extend ModuleCluster::Define::ModuleClusterCascadesToClass
25
+ extend( anonymous_module_cascade_to_class_append_features( extend_or_include, *other_modules ) )
26
+ if is_a?( Class )
27
+ other_modules.each do |this_module|
28
+ __send__( extend_or_include, this_module )
29
+ end
30
+ end
31
+ end
32
+ super( class_or_module )
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ ################################################
40
+ # anonymous_module_cascade_to_class_included #
41
+ ################################################
42
+
43
+ def anonymous_module_cascade_to_class_included( extend_or_include, *other_modules )
44
+
45
+ return Module.new do
46
+
47
+ #------------#
48
+ # included #
49
+ #------------#
50
+
51
+ define_method( :included ) do |class_or_module|
52
+ super( class_or_module )
53
+ class_or_module.module_eval do
54
+ extend ModuleCluster::Define::ModuleClusterCascadesToClass
55
+ extend( anonymous_module_cascade_to_class_included( extend_or_include, *other_modules ) )
56
+ if is_a?( Class )
57
+ other_modules.each do |this_module|
58
+ __send__( extend_or_include, this_module )
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+
68
+ #####################################################
69
+ # anonymous_module_cascade_to_class_extend_object #
70
+ #####################################################
71
+
72
+ def anonymous_module_cascade_to_class_extend_object( extend_or_include, *other_modules )
73
+
74
+ return Module.new do
75
+
76
+ #-----------------#
77
+ # extend_object #
78
+ #-----------------#
79
+
80
+ define_method( :extend_object ) do |class_or_module|
81
+ class_or_module.module_eval do
82
+ extend ModuleCluster::Define::ModuleClusterCascadesToClass
83
+ extend( anonymous_module_cascade_to_class_extend_object( extend_or_include, *other_modules ) )
84
+ if is_a?( Class )
85
+ other_modules.each do |this_module|
86
+ __send__( extend_or_include, this_module )
87
+ end
88
+ end
89
+ end
90
+ super( class_or_module )
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+
97
+ ################################################
98
+ # anonymous_module_cascade_to_class_extended #
99
+ ################################################
100
+
101
+ def anonymous_module_cascade_to_class_extended( extend_or_include, *other_modules )
102
+
103
+ return Module.new do
104
+
105
+ #------------#
106
+ # included #
107
+ #------------#
108
+
109
+ define_method( :extended ) do |class_or_module|
110
+ super( class_or_module )
111
+ class_or_module.module_eval do
112
+ extend ModuleCluster::Define::ModuleClusterCascadesToClass
113
+ extend( anonymous_module_cascade_to_class_extended( extend_or_include, *other_modules ) )
114
+ if is_a?( Class )
115
+ other_modules.each do |this_module|
116
+ __send__( extend_or_include, this_module )
117
+ end
118
+ end
119
+ end
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ end