module-cluster 1.4.6 → 1.4.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -97,7 +97,6 @@ require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclas
97
97
  require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures.rb'
98
98
 
99
99
  require_relative 'module-cluster/_private_/ModuleCluster/ExtendForCascade.rb'
100
- require_relative 'module-cluster/_private_/ModuleCluster/ExtendForCascade/Subclass.rb'
101
100
 
102
101
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb'
103
102
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy.rb'
@@ -6,7 +6,6 @@ module ::ModuleCluster::Define::Block::CascadingModuleOrSubclass
6
6
  include ::ModuleCluster::Define::Block::Subclass
7
7
  include ::ModuleCluster::Suspend::WithoutHooks
8
8
 
9
- extend ::ModuleCluster::ExtendForCascade::Subclass
10
9
  extend ::ModuleCluster::ExtendForCascade
11
10
 
12
11
  ##########################################
@@ -5,7 +5,6 @@ module ::ModuleCluster::Define::Block::ClassOrModuleOrSubclass
5
5
  include ::ModuleCluster::Define::Block::ClassOrModule
6
6
  include ::ModuleCluster::Suspend::WithoutHooks
7
7
 
8
- extend ::ModuleCluster::ExtendForCascade::Subclass
9
8
  extend ::ModuleCluster::ExtendForCascade
10
9
 
11
10
  ##########################
@@ -6,7 +6,6 @@ module ::ModuleCluster::Define::Block::ClassOrSubclass
6
6
  include ::ModuleCluster::Define::Block::Subclass
7
7
  include ::ModuleCluster::Suspend::WithoutHooks
8
8
 
9
- extend ::ModuleCluster::ExtendForCascade::Subclass
10
9
  extend ::ModuleCluster::ExtendForCascade
11
10
 
12
11
  ##########################
@@ -6,7 +6,6 @@ module ::ModuleCluster::Define::Block::ModuleOrSubclass
6
6
  include ::ModuleCluster::Define::Block::Subclass
7
7
  include ::ModuleCluster::Suspend::WithoutHooks
8
8
 
9
- extend ::ModuleCluster::ExtendForCascade::Subclass
10
9
  extend ::ModuleCluster::ExtendForCascade
11
10
 
12
11
  ##########################
@@ -3,18 +3,9 @@ module ::ModuleCluster::Define::Block::Subclass
3
3
 
4
4
  include ::ModuleCluster::CascadeFeatures::ClusterStack
5
5
  include ::ModuleCluster::Suspend::WithoutHooks
6
- extend ::ModuleCluster::Define::Block::Module
7
-
8
- # module_extend do |module_instance|
9
- # module_instance.module_eval do
10
- # extend ::ModuleCluster::Define::Block::Class
11
- # class_include do |class_instance|
12
- # end
13
- # end
14
- # end
15
-
16
- extend ::ModuleCluster::ExtendForCascade::Subclass
17
6
 
7
+ extend ::ModuleCluster::ExtendForCascade
8
+
18
9
  ##########################
19
10
  # self.should_cascade? #
20
11
  ##########################
@@ -55,9 +46,11 @@ module ::ModuleCluster::Define::Block::Subclass
55
46
  ##############
56
47
 
57
48
  def subclass( & runtime_block )
49
+
58
50
  return cluster_stack.subclass( ::ModuleCluster::Define::Block::Subclass,
59
51
  __method__,
60
52
  runtime_block )
53
+
61
54
  end
62
55
 
63
56
  end
@@ -8,8 +8,11 @@ module ::ModuleCluster::CascadeFeatures
8
8
  #####################
9
9
 
10
10
  def append_features( hooked_instance )
11
-
12
- ::ModuleCluster::CascadeFeatures.perform_cascades( self, :prepend_include, hooked_instance, cluster_stack.prepend_include_hooks )
11
+
12
+ ::ModuleCluster::CascadeFeatures.perform_cascades( self,
13
+ :prepend_include,
14
+ hooked_instance,
15
+ cluster_stack.prepend_include_hooks )
13
16
 
14
17
  super
15
18
 
@@ -23,7 +26,21 @@ module ::ModuleCluster::CascadeFeatures
23
26
 
24
27
  super
25
28
 
26
- ::ModuleCluster::CascadeFeatures.perform_cascades( self, :include, hooked_instance, cluster_stack.include_hooks )
29
+ ::ModuleCluster::CascadeFeatures.perform_cascades( self,
30
+ :include,
31
+ hooked_instance,
32
+ cluster_stack.include_hooks )
33
+
34
+ # if we are included in a class and we have cascading inherit hooks we need to move them over
35
+ # append_features and included are both called for an inlucde, so we only need to do this in one
36
+ if hooked_instance.is_a?( Class )
37
+
38
+ unless cluster_stack.inherited_hooks.empty?
39
+ hooked_instance.extend( ::ModuleCluster::Define::Block::Subclass )
40
+ hooked_instance.cluster_stack.inherited_hooks.concat( cluster_stack.inherited_hooks )
41
+ end
42
+
43
+ end
27
44
 
28
45
  end
29
46
 
@@ -33,7 +50,10 @@ module ::ModuleCluster::CascadeFeatures
33
50
 
34
51
  def extend_object( hooked_instance )
35
52
 
36
- ::ModuleCluster::CascadeFeatures.perform_cascades( self, :prepend_extend, hooked_instance, cluster_stack.prepend_extend_hooks )
53
+ ::ModuleCluster::CascadeFeatures.perform_cascades( self,
54
+ :prepend_extend,
55
+ hooked_instance,
56
+ cluster_stack.prepend_extend_hooks )
37
57
 
38
58
  super
39
59
 
@@ -47,7 +67,10 @@ module ::ModuleCluster::CascadeFeatures
47
67
 
48
68
  super
49
69
 
50
- ::ModuleCluster::CascadeFeatures.perform_cascades( self, :extend, hooked_instance, cluster_stack.extend_hooks )
70
+ ::ModuleCluster::CascadeFeatures.perform_cascades( self,
71
+ :extend,
72
+ hooked_instance,
73
+ cluster_stack.extend_hooks )
51
74
 
52
75
  end
53
76
 
@@ -1,7 +1,6 @@
1
1
 
2
2
  module ::ModuleCluster::CascadeFeatures::PerformCascades
3
3
 
4
- $this_time = 0
5
4
  ######################
6
5
  # perform_cascades #
7
6
  ######################
@@ -26,7 +25,7 @@ module ::ModuleCluster::CascadeFeatures::PerformCascades
26
25
 
27
26
  # if our blocks are set to cascade then we need to copy inherit hooks
28
27
  if this_set.dependency_module.should_cascade?( hooked_instance )
29
- cascade_block_into_hooked_instance( module_self, hooked_instance, this_set )
28
+ cascade_block_into_hooked_instance( module_self, action, hooked_instance, this_set )
30
29
  end
31
30
 
32
31
  if this_set.dependency_module.should_run_block?( hooked_instance )
@@ -129,20 +128,27 @@ module ::ModuleCluster::CascadeFeatures::PerformCascades
129
128
  # cascade_block_into_hooked_instance #
130
129
  ########################################
131
130
 
132
- def cascade_block_into_hooked_instance( module_self, hooked_instance, set )
131
+ def cascade_block_into_hooked_instance( module_self, action, hooked_instance, set )
132
+
133
+ hooked_instance.extend( set.dependency_module )
134
+
135
+ if hooked_instance.is_a?( Class )
136
+
137
+ if action == :inherited
133
138
 
134
- # subclasses already cascade due to #inherited behavior
135
- unless hooked_instance.is_a?( Class )
139
+ unless set.dependency_module == ::ModuleCluster::CascadeFeatures::Subclass
140
+ hooked_instance.extend( ::ModuleCluster::CascadeFeatures::Subclass )
141
+ end
142
+
143
+ hooked_instance.subclass( & set.runtime_block )
136
144
 
137
- # if we are supposed to cascade we need to extend with the ::ModuleCluster dependency module
138
- hooked_instance.extend( set.dependency_module )
145
+ end
146
+
147
+ else
139
148
 
140
149
  # and we call the set's definition method to cascade
141
150
  hooked_instance.__send__( set.method, & set.runtime_block )
142
151
 
143
- existing_inherit_hooks = module_self.cluster_stack.inherited_hooks
144
- hooked_instance.cluster_stack.inherited_hooks.concat( existing_inherit_hooks )
145
-
146
152
  end
147
153
 
148
154
  end
@@ -1,6 +1,8 @@
1
1
 
2
2
  module ::ModuleCluster::CascadeFeatures::Subclass
3
3
 
4
+ extend ::ModuleCluster::CascadeFeatures::PerformCascades
5
+
4
6
  ###############
5
7
  # inherited #
6
8
  ###############
@@ -6,15 +6,29 @@ module ::ModuleCluster::ExtendForCascade
6
6
  ##############
7
7
 
8
8
  def extended( module_cluster_configuration_instance )
9
+
9
10
  super
10
- module_cluster_configuration_instance.module_eval do
11
- # when a module-cluster definition module is used to extend a module,
12
- # define self#extended, self#included, self#append_features, self#extend_object in
13
- # module_cluster_module ( module extended with module-cluster definition module )
14
- extend ::ModuleCluster::CascadeFeatures
15
- # classes and instances can't cascade through include/extend, so no reason to define
16
- # unless we have a module
17
- end if module_cluster_configuration_instance.is_a?( Module ) and ! module_cluster_configuration_instance.is_a?( Class )
11
+
12
+ if module_cluster_configuration_instance.is_a?( Class )
13
+
14
+ module_cluster_configuration_instance.module_eval do
15
+ # when a module-cluster definition module is used to extend a module,
16
+ # define self#extended, self#included, self#append_features, self#extend_object in
17
+ # module_cluster_module ( module extended with module-cluster definition module )
18
+ extend ::ModuleCluster::CascadeFeatures::Subclass
19
+ end
20
+
21
+ else
22
+
23
+ module_cluster_configuration_instance.instance_eval do
24
+ # when a module-cluster definition module is used to extend a module,
25
+ # define self#extended, self#included, self#append_features, self#extend_object in
26
+ # module_cluster_module ( module extended with module-cluster definition module )
27
+ extend ::ModuleCluster::CascadeFeatures
28
+ end
29
+
30
+ end
31
+
18
32
  end
19
33
 
20
34
  end
@@ -14,12 +14,21 @@ describe ::ModuleCluster::Define::Block::CascadingClass do
14
14
  cascading_class_include do
15
15
  block_ran = true
16
16
  end
17
+ cluster_stack.inherited_hooks.count.should == 1
17
18
  respond_to?( :included ).should == true
18
19
  module ModuleProof
19
20
  include ::ModuleCluster::Define::Block::CascadingClass::Mock01
21
+ respond_to?( :cluster_stack ).should == true
22
+ cluster_stack.inherited_hooks.count.should == 1
20
23
  end
21
24
  block_ran.should == false
22
25
  module ModuleProof2
26
+ include ::ModuleCluster::Define::Block::CascadingClass::Mock01::ModuleProof
27
+ respond_to?( :cluster_stack ).should == true
28
+ cluster_stack.inherited_hooks.count.should == 1
29
+ end
30
+ block_ran.should == false
31
+ module ModuleProofExtended
23
32
  extend ::ModuleCluster::Define::Block::CascadingClass::Mock01
24
33
  end
25
34
  block_ran.should == false
@@ -33,10 +42,14 @@ describe ::ModuleCluster::Define::Block::CascadingClass do
33
42
  block_ran.should == false
34
43
  class CascadingClassProof
35
44
  include ::ModuleCluster::Define::Block::CascadingClass::Mock01
45
+ respond_to?( :cluster_stack ).should == true
46
+ cluster_stack.inherited_hooks.count.should == 1
36
47
  end
37
48
  block_ran.should == true
38
49
  block_ran = false
39
50
  class CascadingClassProof2 < CascadingClassProof
51
+ respond_to?( :cluster_stack ).should == true
52
+ cluster_stack.inherited_hooks.count.should == 1
40
53
  end
41
54
  block_ran.should == true
42
55
  end
@@ -15,25 +15,31 @@ describe ::ModuleCluster::Define::Block::Module do
15
15
  block_ran = true
16
16
  self.should == ::ModuleCluster::Define::Block::Module::Mock01
17
17
  end
18
+ cluster_stack.include_hooks.count.should == 1
18
19
  respond_to?( :included ).should == true
19
20
  class ClassProof
20
21
  extend ::ModuleCluster::Define::Block::Module::Mock01
22
+ respond_to?( :cluster_stack ).should == false
21
23
  end
22
24
  block_ran.should == false
23
25
  class ClassProof2
24
26
  include ::ModuleCluster::Define::Block::Module::Mock01
27
+ respond_to?( :cluster_stack ).should == false
25
28
  end
26
29
  block_ran.should == false
27
30
  Object.new.instance_eval do
28
31
  extend ::ModuleCluster::Define::Block::Module::Mock01
32
+ respond_to?( :cluster_stack ).should == false
29
33
  end
30
34
  block_ran.should == false
31
35
  module ModuleProof
32
36
  extend ::ModuleCluster::Define::Block::Module::Mock01
37
+ respond_to?( :cluster_stack ).should == false
33
38
  end
34
39
  block_ran.should == false
35
40
  module ModuleProof2
36
41
  include ::ModuleCluster::Define::Block::Module::Mock01
42
+ respond_to?( :cluster_stack ).should == false
37
43
  end
38
44
  block_ran.should == true
39
45
  end
@@ -46,8 +46,9 @@ describe ::ModuleCluster::Define::Block::Subclass do
46
46
  end
47
47
  respond_to?( :included ).should == true
48
48
  respond_to?( :extended ).should == true
49
- respond_to?( :append_features ).should == false
50
- respond_to?( :extend_object ).should == false
49
+ respond_to?( :append_features ).should == true
50
+ respond_to?( :extend_object ).should == true
51
+ respond_to?( :inherited ).should == false
51
52
  class ClassProof
52
53
  include ::ModuleCluster::Define::Block::Subclass::Mock02
53
54
  respond_to?( :inherited ).should == true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: module-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.6
4
+ version: 1.4.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -42,7 +42,6 @@ files:
42
42
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Status.rb
43
43
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Suspend.rb
44
44
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack.rb
45
- - lib/module-cluster/_private_/ModuleCluster/ExtendForCascade/Subclass.rb
46
45
  - lib/module-cluster/_private_/ModuleCluster/ExtendForCascade.rb
47
46
  - lib/module-cluster/ModuleCluster/Define/Block/CascadingClass.rb
48
47
  - lib/module-cluster/ModuleCluster/Define/Block/CascadingClassOrModule.rb
@@ -1,68 +0,0 @@
1
-
2
- module ::ModuleCluster::ExtendForCascade::Subclass
3
-
4
- ##############
5
- # extended #
6
- ##############
7
-
8
- def extended( module_cluster_configuration_class_instance )
9
-
10
- super
11
-
12
- if module_cluster_configuration_class_instance.is_a?( Class )
13
-
14
- module_cluster_configuration_class_instance.module_eval do
15
- # when a module-cluster definition module is used to extend a module,
16
- # define self#inherited module_cluster_configuration_class_instance
17
- # (class extended with module-cluster definition module)
18
- extend ::ModuleCluster::CascadeFeatures::Subclass
19
- end
20
-
21
- elsif module_cluster_configuration_class_instance.is_a?( Module )
22
-
23
- # we need to create an include hook in the module so that when the class includes it,
24
- # it gets the subclass definition
25
- module_cluster_configuration_class_instance.module_eval do
26
- # when a module is enabled for subclass we need to cascade subclassing
27
- extend ::ModuleCluster::ExtendForCascade::Subclass
28
- end
29
-
30
- end
31
-
32
- end
33
-
34
- ##############
35
- # included #
36
- ##############
37
-
38
- def included( module_cluster_configuration_class_instance )
39
-
40
- super
41
-
42
- existing_inherited_hooks = cluster_stack.inherited_hooks
43
-
44
- if module_cluster_configuration_class_instance.is_a?( Class )
45
-
46
- module_cluster_configuration_class_instance.module_eval do
47
- # when a module-cluster definition module is used to extend a module,
48
- # define self#inherited module_cluster_configuration_class_instance
49
- # (class extended with module-cluster definition module)
50
- extend ::ModuleCluster::Define::Block::Subclass
51
- cluster_stack.inherited_hooks.concat( existing_inherited_hooks )
52
- end
53
-
54
- elsif module_cluster_configuration_class_instance.is_a?( Module )
55
-
56
- # we need to create an include hook in the module so that when the class includes it,
57
- # it gets the subclass definition
58
- module_cluster_configuration_class_instance.module_eval do
59
- # when a module is enabled for subclass we need to cascade subclassing
60
- extend ::ModuleCluster::Define::Block::Subclass
61
- cluster_stack.inherited_hooks.concat( existing_inherited_hooks )
62
- end
63
-
64
- end
65
-
66
- end
67
-
68
- end