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
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- - 1
9
- version: 1.1.1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Asher
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-25 00:00:00 -04:00
17
+ date: 2011-07-31 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: Provides :define_module_included, :define_module_extended, :define_module_cluster, :define_module_included_cascades, :define_module_extended_cascades, :define_module_cluster_cascades, :define_module_included_cascades_to_class, :define_module_extended_cascades_to_class, :define_module_cluster_cascades_to_class.
21
+ 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
22
  email: asher@ridiculouspower.com
23
23
  executables: []
24
24
 
@@ -27,14 +27,23 @@ extensions: []
27
27
  extra_rdoc_files: []
28
28
 
29
29
  files:
30
- - lib/module-cluster/_private_/ModuleCluster.rb
31
- - lib/module-cluster/ModuleCluster/_private_/IncludeExtendSupport.rb
32
- - lib/module-cluster/ModuleCluster/ExtendSupport.rb
33
- - lib/module-cluster/ModuleCluster/IncludeExtendSupport.rb
34
- - lib/module-cluster/ModuleCluster/IncludeSupport.rb
30
+ - lib/module-cluster/ModuleCluster/Define/_private_/ClusterStack.rb
31
+ - lib/module-cluster/ModuleCluster/Define/_private_/ModuleCluster.rb
32
+ - lib/module-cluster/ModuleCluster/Define/_private_/ModuleClusterCascades.rb
33
+ - lib/module-cluster/ModuleCluster/Define/_private_/ModuleClusterCascadesToClass.rb
34
+ - lib/module-cluster/ModuleCluster/Define/Deprecated.rb
35
+ - lib/module-cluster/ModuleCluster/Define/ModuleCluster.rb
36
+ - lib/module-cluster/ModuleCluster/Define/ModuleClusterCascades.rb
37
+ - lib/module-cluster/ModuleCluster/Define/ModuleClusterCascadesToClass.rb
35
38
  - lib/module-cluster/ModuleCluster.rb
36
39
  - lib/module-cluster.rb
37
- - spec/ModuleCluster/IncludeExtendSupport_spec.rb
40
+ - spec/ModuleCluster/Define/_private_/ClusterStack_spec.rb
41
+ - spec/ModuleCluster/Define/_private_/ModuleCluster_spec.rb
42
+ - spec/ModuleCluster/Define/_private_/ModuleClusterCascades_spec.rb
43
+ - spec/ModuleCluster/Define/_private_/ModuleClusterCascadesToClass_spec.rb
44
+ - spec/ModuleCluster/Define/ModuleCluster_spec.rb
45
+ - spec/ModuleCluster/Define/ModuleClusterCascades_spec.rb
46
+ - spec/ModuleCluster/Define/ModuleClusterCascadesToClass_spec.rb
38
47
  - spec/ModuleCluster_spec.rb
39
48
  - README.md
40
49
  - README.rdoc
@@ -69,6 +78,6 @@ rubyforge_project: module-cluster
69
78
  rubygems_version: 1.3.7
70
79
  signing_key:
71
80
  specification_version: 3
72
- summary: "Adds methods for defining module clusters using #included and #extended."
81
+ summary: "Adds methods for defining module clusters using #included, #extended, #append_features, and #extend_object."
73
82
  test_files: []
74
83
 
@@ -1,95 +0,0 @@
1
-
2
- module ModuleCluster::ExtendSupport
3
-
4
- extend ModuleCluster::IncludeExtendSupport
5
-
6
- ##############
7
- # extended #
8
- ##############
9
-
10
- def extended( class_or_module )
11
- super if defined?( super )
12
- module_self = self
13
- class_or_module.instance_eval do
14
- # cascade ModuleCluster support
15
- extend ModuleCluster
16
- # take care of anything we're supposed to include when we are extended
17
- ModuleCluster::ExtendSupport.included_sets( module_self ).each do |this_set|
18
- # if we have a set intended to cascade only to classes
19
- if this_set.is_a?( Array::CascadeToClass ) or this_set.is_a?( Array::CascadeToClassOrModule )
20
- # and we have a class
21
- if is_a?( Class ) or this_set.is_a?( Array::CascadeToClassOrModule )
22
- # include the set
23
- include( *this_set )
24
- end
25
- unless is_a?( Class )
26
- if this_set.is_a?( Array::CascadeToClass )
27
- # cascade our includes to the next module
28
- define_module_extended_cascades_to_class do |included, extended|
29
- included.concat( this_set )
30
- end
31
- if ModuleCluster::ExtendSupport.include_cluster?( module_self, *this_set )
32
- define_module_included_cascades_to_class do |included, extended|
33
- included.concat( this_set )
34
- end
35
- end
36
- else
37
- # cascade our includes to the next module
38
- define_module_extended_cascades do |included, extended|
39
- included.concat( this_set )
40
- end
41
- if ModuleCluster::ExtendSupport.include_cluster?( module_self, *this_set )
42
- define_module_included_cascades do |included, extended|
43
- included.concat( this_set )
44
- end
45
- end
46
- end
47
- end
48
- # otherwise
49
- else
50
- # include the set
51
- include( *this_set )
52
- end
53
- end
54
- # take care of anything we're supposed to extend when we are extended
55
- ModuleCluster::ExtendSupport.extended_sets( module_self ).each do |this_set|
56
- # if we have a set intended to cascade only to classes
57
- if this_set.is_a?( Array::CascadeToClass ) or this_set.is_a?( Array::CascadeToClassOrModule )
58
- # and we have a class
59
- if is_a?( Class ) or this_set.is_a?( Array::CascadeToClassOrModule )
60
- # extend the set
61
- extend( *this_set )
62
- end
63
- unless is_a?( Class )
64
- if this_set.is_a?( Array::CascadeToClass )
65
- # cascade our extends to the next module
66
- define_module_extended_cascades_to_class do |included, extended|
67
- extended.concat( this_set )
68
- end
69
- if ModuleCluster::ExtendSupport.extend_cluster?( module_self, *this_set )
70
- define_module_included_cascades_to_class do |included, extended|
71
- extended.concat( this_set )
72
- end
73
- end
74
- else
75
- # cascade our extends to the next module
76
- define_module_extended_cascades do |included, extended|
77
- extended.concat( this_set )
78
- end
79
- if ModuleCluster::ExtendSupport.extend_cluster?( module_self, *this_set )
80
- define_module_included_cascades do |included, extended|
81
- extended.concat( this_set )
82
- end
83
- end
84
- end
85
- end
86
- # otherwise
87
- else
88
- # extend the set
89
- extend( *this_set )
90
- end
91
- end
92
- end
93
- end
94
-
95
- end
@@ -1,104 +0,0 @@
1
-
2
- module ModuleCluster::IncludeExtendSupport
3
-
4
- ######################################
5
- # add_includes_for_class_or_module #
6
- ######################################
7
-
8
- def add_includes_for_class_or_module( class_or_module, includes )
9
- included_sets( class_or_module ).push( includes ) unless includes.empty?
10
- end
11
-
12
- #####################################
13
- # add_extends_for_class_or_module #
14
- #####################################
15
-
16
- def add_extends_for_class_or_module( class_or_module, extends )
17
- extended_sets( class_or_module ).push( extends ) unless extends.empty?
18
- end
19
-
20
- ################################################
21
- # add_cascading_includes_for_class_or_module #
22
- ################################################
23
-
24
- def add_cascading_includes_for_class_or_module( class_or_module, includes )
25
- included_sets( class_or_module ).push( includes ) unless includes.empty?
26
- end
27
-
28
- ###############################################
29
- # add_cascading_extends_for_class_or_module #
30
- ###############################################
31
-
32
- def add_cascading_extends_for_class_or_module( class_or_module, extends )
33
- extended_sets( class_or_module ).push( extends ) unless extends.empty?
34
- end
35
-
36
- ######################################
37
- # add_cascading_includes_for_class #
38
- ######################################
39
-
40
- def add_cascading_includes_for_class( klass, includes )
41
- included_sets( klass ).push( includes ) unless includes.empty?
42
- end
43
-
44
- #####################################
45
- # add_cascading_extends_for_class #
46
- #####################################
47
-
48
- def add_cascading_extends_for_class( klass, extends )
49
- extended_sets( klass ).push( extends ) unless extends.empty?
50
- end
51
-
52
- ###################
53
- # included_sets #
54
- ###################
55
-
56
- def included_sets( class_or_module )
57
- return included_sets_hash[ class_or_module ] ||= Array.new
58
- end
59
-
60
- ###################
61
- # extended_sets #
62
- ###################
63
-
64
- def extended_sets( class_or_module )
65
- return extended_sets_hash[ class_or_module ] ||= Array.new
66
- end
67
-
68
- ####################
69
- # set_as_cluster #
70
- ####################
71
-
72
- def set_as_cluster( class_or_module, includes, extends )
73
- includes_cluster_hash_for_class_or_module( class_or_module ).concat( includes )
74
- extends_cluster_hash_for_class_or_module( class_or_module ).concat( extends )
75
- return self
76
- end
77
-
78
- ######################
79
- # include_cluster? #
80
- ######################
81
-
82
- def include_cluster?( class_or_module, *modules )
83
- include_set_as_cluster = true
84
- modules.each do |this_module|
85
- include_set_as_cluster = false unless includes_cluster_hash_for_class_or_module( class_or_module ).include?( this_module )
86
- break unless include_set_as_cluster
87
- end
88
- return include_set_as_cluster
89
- end
90
-
91
- #####################
92
- # extend_cluster? #
93
- #####################
94
-
95
- def extend_cluster?( class_or_module, *modules )
96
- extend_set_as_cluster = true
97
- modules.each do |this_module|
98
- extend_set_as_cluster = false unless extends_cluster_hash_for_class_or_module( class_or_module ).include?( this_module )
99
- break unless extend_set_as_cluster
100
- end
101
- return extend_set_as_cluster
102
- end
103
-
104
- end
@@ -1,94 +0,0 @@
1
-
2
- module ModuleCluster::IncludeSupport
3
-
4
- extend ModuleCluster::IncludeExtendSupport
5
-
6
- ##############
7
- # included #
8
- ##############
9
-
10
- def included( class_or_module )
11
- super if defined?( super )
12
- module_self = self
13
- class_or_module.instance_eval do
14
- # cascade ModuleCluster support
15
- extend ModuleCluster
16
- ModuleCluster::IncludeSupport.included_sets( module_self ).each do |this_set|
17
- # if we have a set intended to cascade only to classes
18
- if this_set.is_a?( Array::CascadeToClass ) or this_set.is_a?( Array::CascadeToClassOrModule )
19
- # and we have a class
20
- if is_a?( Class ) or this_set.is_a?( Array::CascadeToClassOrModule )
21
- # include the set
22
- include( *this_set )
23
- end
24
- unless is_a?( Class )
25
- if this_set.is_a?( Array::CascadeToClass )
26
- # cascade our includes to the next module
27
- define_module_included_cascades_to_class do |included, extended|
28
- included.concat( this_set )
29
- end
30
- if ModuleCluster::IncludeSupport.include_cluster?( module_self, *this_set )
31
- define_module_extended_cascades_to_class do |included, extended|
32
- included.concat( this_set )
33
- end
34
- end
35
- else
36
- # cascade our includes to the next module
37
- define_module_included_cascades do |included, extended|
38
- included.concat( this_set )
39
- end
40
- if ModuleCluster::IncludeSupport.include_cluster?( module_self, *this_set )
41
- define_module_extended_cascades do |included, extended|
42
- included.concat( this_set )
43
- end
44
- end
45
- end
46
- end
47
- # otherwise
48
- else
49
- # include the set
50
- include( *this_set )
51
- end
52
- end
53
- # take care of anything we're supposed to extend when we are included
54
- ModuleCluster::IncludeSupport.extended_sets( module_self ).each do |this_set|
55
- # if we have a set intended to cascade only to classes
56
- if this_set.is_a?( Array::CascadeToClass ) or this_set.is_a?( Array::CascadeToClassOrModule )
57
- # and we have a class
58
- if is_a?( Class ) or this_set.is_a?( Array::CascadeToClassOrModule )
59
- # extend the set
60
- extend( *this_set )
61
- end
62
- unless is_a?( Class )
63
- if this_set.is_a?( Array::CascadeToClass )
64
- # cascade our extends to the next module
65
- define_module_included_cascades_to_class do |included, extended|
66
- extended.concat( this_set )
67
- end
68
- if ModuleCluster::IncludeSupport.extend_cluster?( module_self, *this_set )
69
- define_module_extended_cascades_to_class do |included, extended|
70
- extended.concat( this_set )
71
- end
72
- end
73
- else
74
- # cascade our extends to the next module
75
- define_module_included_cascades do |included, extended|
76
- extended.concat( this_set )
77
- end
78
- if ModuleCluster::IncludeSupport.extend_cluster?( module_self, *this_set )
79
- define_module_extended_cascades do |included, extended|
80
- extended.concat( this_set )
81
- end
82
- end
83
- end
84
- end
85
- # otherwise
86
- else
87
- # extend the set
88
- extend( *this_set )
89
- end
90
- end
91
- end
92
- end
93
-
94
- end
@@ -1,56 +0,0 @@
1
-
2
- module ModuleCluster::IncludeExtendSupport
3
-
4
- ###########################################################################################################
5
- private ###############################################################################################
6
- ###########################################################################################################
7
-
8
- ########################
9
- # included_sets_hash #
10
- ########################
11
-
12
- def included_sets_hash
13
- return @included_sets_hash ||= Hash.new
14
- end
15
-
16
- ########################
17
- # extended_sets_hash #
18
- ########################
19
-
20
- def extended_sets_hash
21
- return @extended_sets_hash ||= Hash.new
22
- end
23
-
24
- ##################
25
- # cluster_hash #
26
- ##################
27
-
28
- def cluster_hash
29
- return @cluster_hash ||= Hash.new
30
- end
31
-
32
- ######################################
33
- # cluster_hash_for_class_or_module #
34
- ######################################
35
-
36
- def cluster_hash_for_class_or_module( class_or_module )
37
- return cluster_hash[ class_or_module ] ||= Hash.new
38
- end
39
-
40
- ###############################################
41
- # includes_cluster_hash_for_class_or_module #
42
- ###############################################
43
-
44
- def includes_cluster_hash_for_class_or_module( class_or_module )
45
- return cluster_hash_for_class_or_module( class_or_module )[ :includes ] ||= Array.new
46
- end
47
-
48
- ##############################################
49
- # extends_cluster_hash_for_class_or_module #
50
- ##############################################
51
-
52
- def extends_cluster_hash_for_class_or_module( class_or_module )
53
- return cluster_hash_for_class_or_module( class_or_module )[ :extends ] ||= Array.new
54
- end
55
-
56
- end
@@ -1,23 +0,0 @@
1
-
2
- module ModuleCluster
3
-
4
- ###########################################################################################################
5
- private ###############################################################################################
6
- ###########################################################################################################
7
-
8
- def yield_for_includes_extends( inclusion_array, extension_array, block )
9
- returned_includes, returned_extends = block.call( inclusion_array, extension_array )
10
- if returned_includes and returned_extends and
11
- returned_includes.is_a?( Array ) and returned_extends.is_a?( Array )
12
- inclusion_array = returned_includes
13
- extension_array = returned_extends
14
- end
15
- unless inclusion_array.is_a?( Array ) and extension_array.is_a?( Array )
16
- raise 'Expected module inclusion/extension variables to remain Array. Received ' +
17
- inclusion_array.inspect + ' for inclusion array, and ' + extension_array.inspect +
18
- ' for extension array.'
19
- end
20
- return inclusion_array, extension_array
21
- end
22
-
23
- end
@@ -1,46 +0,0 @@
1
-
2
- require_relative '../../lib/module-cluster.rb'
3
-
4
- describe ModuleCluster::IncludeExtendSupport do
5
-
6
- ############################################
7
- # set_includes_for_class_or_module #
8
- # includes_for_class_or_module_inclusion #
9
- ############################################
10
-
11
- it 'can set and return includes for a class or module' do
12
- module ModuleCluster::IncludeExtendSupport::Mock01
13
- extend ModuleCluster::IncludeExtendSupport
14
- module MockModule1
15
- end
16
- module MockModule2
17
- end
18
- end
19
- class ModuleCluster::IncludeExtendSupport::MockClass
20
- includes = [ ModuleCluster::IncludeExtendSupport::Mock01::MockModule1,
21
- ModuleCluster::IncludeExtendSupport::Mock01::MockModule2 ]
22
- ModuleCluster::IncludeExtendSupport::Mock01.add_includes_for_class_or_module( self, includes )
23
- end
24
- end
25
-
26
- ###########################################
27
- # set_extends_for_class_or_module #
28
- # extends_for_class_or_module_extension #
29
- ###########################################
30
-
31
- it 'can set and return extends for a class or module' do
32
- module ModuleCluster::IncludeExtendSupport::Mock02
33
- extend ModuleCluster::IncludeExtendSupport
34
- module MockModule1
35
- end
36
- module MockModule2
37
- end
38
- end
39
- class ModuleCluster::IncludeExtendSupport::MockClass
40
- includes = [ ModuleCluster::IncludeExtendSupport::Mock02::MockModule1,
41
- ModuleCluster::IncludeExtendSupport::Mock02::MockModule2 ]
42
- ModuleCluster::IncludeExtendSupport::Mock02.add_includes_for_class_or_module( self, includes )
43
- end
44
- end
45
-
46
- end