module-cluster 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,8 @@ module ModuleCluster
8
8
  end
9
9
  module Module
10
10
  end
11
+ module Inherited
12
+ end
11
13
  end
12
14
  module Status
13
15
  end
@@ -15,6 +17,16 @@ module ModuleCluster
15
17
  end
16
18
  end
17
19
  module CascadeFeatures
20
+ module Subclass
21
+ end
22
+ module ClusterStack
23
+ end
24
+ module PerformCascades
25
+ end
26
+ end
27
+ module ExtendForCascade
28
+ module Subclass
29
+ end
18
30
  end
19
31
  module Define
20
32
  module Block
@@ -67,9 +79,11 @@ end
67
79
 
68
80
  require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb'
69
81
  require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb'
82
+ require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclass.rb'
70
83
  require_relative 'module-cluster/_private_/ModuleCluster/CascadeFeatures.rb'
71
84
 
72
85
  require_relative 'module-cluster/_private_/ModuleCluster/ExtendForCascade.rb'
86
+ require_relative 'module-cluster/_private_/ModuleCluster/ExtendForCascade/Subclass.rb'
73
87
 
74
88
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Set.rb'
75
89
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Set/MultiSetProxy.rb'
@@ -80,6 +94,7 @@ require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Extends.rb
80
94
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/PrependsIncludes.rb'
81
95
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/PrependsExtends.rb'
82
96
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb'
97
+ require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Inherited.rb'
83
98
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb'
84
99
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb'
85
100
  require_relative 'module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb'
@@ -91,6 +106,7 @@ require_relative 'module-cluster/ModuleCluster/Suspend/WithoutHooks.rb'
91
106
  require_relative 'module-cluster/ModuleCluster/Suspend.rb'
92
107
 
93
108
  require_relative 'module-cluster/ModuleCluster/Define/Block/Class.rb'
109
+ require_relative 'module-cluster/ModuleCluster/Define/Block/Subclass.rb'
94
110
  require_relative 'module-cluster/ModuleCluster/Define/Block/Instance.rb'
95
111
  require_relative 'module-cluster/ModuleCluster/Define/Block/Module.rb'
96
112
  require_relative 'module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb'
@@ -0,0 +1,25 @@
1
+
2
+ module ModuleCluster::Define::Block::Subclass
3
+
4
+ include ModuleCluster::CascadeFeatures::ClusterStack
5
+ include ModuleCluster::Suspend::WithoutHooks
6
+
7
+ extend ModuleCluster::ExtendForCascade::Subclass
8
+
9
+ ############################
10
+ # self.should_run_block? #
11
+ ############################
12
+
13
+ def self.should_run_block?( hooked_instance )
14
+ return hooked_instance.is_a?( Class )
15
+ end
16
+
17
+ ##############
18
+ # subclass #
19
+ ##############
20
+
21
+ def subclass( & runtime_block )
22
+ return cluster_stack.subclass( ModuleCluster::Define::Block::Subclass, runtime_block )
23
+ end
24
+
25
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module ModuleCluster::CascadeFeatures::Subclass
3
+
4
+ ###############
5
+ # inherited #
6
+ ###############
7
+
8
+ def inherited( hooked_instance )
9
+
10
+ # all future subclasses should receive cascading hook
11
+ hooked_instance.extend( ModuleCluster::CascadeFeatures::Subclass )
12
+ hooked_instance.cluster_stack.inherited_hooks.concat( cluster_stack.inherited_hooks )
13
+
14
+ ModuleCluster::CascadeFeatures.perform_cascades( self, :inherited, hooked_instance, cluster_stack.inherited_hooks )
15
+
16
+ super
17
+
18
+ end
19
+
20
+ end
@@ -4,5 +4,6 @@ module ModuleCluster::ClusterStack::Block
4
4
  include Class
5
5
  include Module
6
6
  include Instance
7
-
7
+ include Inherited
8
+
8
9
  end
@@ -0,0 +1,20 @@
1
+
2
+ module ModuleCluster::ClusterStack::Block::Inherited
3
+
4
+ #####################
5
+ # inherited_hooks #
6
+ #####################
7
+
8
+ def inherited_hooks
9
+ return @inherited_hooks ||= ::ModuleCluster::ClusterStack::Set::MultiSetProxy.new
10
+ end
11
+
12
+ ##############
13
+ # subclass #
14
+ ##############
15
+
16
+ def subclass( dependency_module, runtime_block )
17
+ inherited_hooks.push( ModuleCluster::ClusterStack::Block::Set.new( dependency_module, runtime_block ) )
18
+ end
19
+
20
+ end
@@ -5,16 +5,16 @@ module ModuleCluster::ExtendForCascade
5
5
  # extended #
6
6
  ##############
7
7
 
8
- def extended( module_cluster_module )
8
+ def extended( module_cluster_configuration_instance )
9
9
  super
10
- module_cluster_module.module_eval do
10
+ module_cluster_configuration_instance.module_eval do
11
11
  # when a module-cluster definition module is used to extend a module,
12
12
  # define self#extended, self#included, self#append_features, self#extend_object in
13
13
  # module_cluster_module ( module extended with module-cluster definition module )
14
14
  extend ModuleCluster::CascadeFeatures
15
15
  # classes and instances can't cascade through include/extend, so no reason to define
16
16
  # unless we have a module
17
- end if module_cluster_module.is_a?( Module ) and ! module_cluster_module.is_a?( Class )
17
+ end if module_cluster_configuration_instance.is_a?( Module ) and ! module_cluster_configuration_instance.is_a?( Class )
18
18
  end
19
19
 
20
20
  end
@@ -0,0 +1,21 @@
1
+
2
+ module ModuleCluster::ExtendForCascade::Subclass
3
+
4
+ ##############
5
+ # extended #
6
+ ##############
7
+
8
+ def extended( module_cluster_configuration_class_instance )
9
+ unless module_cluster_configuration_class_instance.is_a?( Class )
10
+ raise ArgumentError, 'Module-cluster blocks cannot be defined for subclassing on non-class objects.'
11
+ end
12
+ super
13
+ module_cluster_configuration_class_instance.module_eval do
14
+ # when a module-cluster definition module is used to extend a module,
15
+ # define self#inherited module_cluster_configuration_class_instance
16
+ # (class extended with module-cluster definition module)
17
+ extend ModuleCluster::CascadeFeatures::Subclass
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,42 @@
1
+
2
+ require_relative '../../../../lib/module-cluster.rb'
3
+
4
+ describe ModuleCluster::Define::Block::Subclass do
5
+
6
+ ##############
7
+ # subclass #
8
+ ##############
9
+
10
+ it 'can run a block when a class is subclassed' do
11
+
12
+ # Modules shouldn't work
13
+ Proc.new do
14
+ module ModuleCluster::Define::Block::Subclass::ModuleMock01
15
+ extend ModuleCluster::Define::Block::Subclass
16
+ end
17
+ end.should raise_error
18
+
19
+ class ModuleCluster::Define::Block::Subclass::Mock01
20
+ extend ModuleCluster::Define::Block::Subclass
21
+ block_ran = false
22
+ subclass do |subclass_instance|
23
+ self.ancestors.include?( ModuleCluster::Define::Block::Subclass::Mock01 ).should == true
24
+ subclass_instance.ancestors.include?( ModuleCluster::Define::Block::Subclass::Mock01 ).should == true
25
+ block_ran = true
26
+ end
27
+ respond_to?( :inherited ).should == true
28
+ respond_to?( :included ).should == false
29
+ respond_to?( :extended ).should == false
30
+ respond_to?( :append_features ).should == false
31
+ respond_to?( :extend_object ).should == false
32
+ class ModuleProof < ModuleCluster::Define::Block::Subclass::Mock01
33
+ end
34
+ block_ran.should == true
35
+ block_ran = false
36
+ class ModuleProof2 < ModuleProof
37
+ end
38
+ block_ran.should == true
39
+ end
40
+ end
41
+
42
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: module-cluster
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.4.2
5
+ version: 1.4.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Asher
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-01-08 00:00:00 Z
13
+ date: 2012-01-11 00:00:00 Z
14
14
  dependencies: []
15
15
 
16
16
  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)."
@@ -24,8 +24,10 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/ClusterStack.rb
26
26
  - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/PerformCascades.rb
27
+ - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures/Subclass.rb
27
28
  - lib/module-cluster/_private_/ModuleCluster/CascadeFeatures.rb
28
29
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Class.rb
30
+ - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Inherited.rb
29
31
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Instance.rb
30
32
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Module.rb
31
33
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Block/Set.rb
@@ -39,6 +41,7 @@ files:
39
41
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Status.rb
40
42
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack/Suspend.rb
41
43
  - lib/module-cluster/_private_/ModuleCluster/ClusterStack.rb
44
+ - lib/module-cluster/_private_/ModuleCluster/ExtendForCascade/Subclass.rb
42
45
  - lib/module-cluster/_private_/ModuleCluster/ExtendForCascade.rb
43
46
  - lib/module-cluster/ModuleCluster/Define/Block/Class.rb
44
47
  - lib/module-cluster/ModuleCluster/Define/Block/ClassOrInstance.rb
@@ -47,6 +50,7 @@ files:
47
50
  - lib/module-cluster/ModuleCluster/Define/Block/Instance.rb
48
51
  - lib/module-cluster/ModuleCluster/Define/Block/Module.rb
49
52
  - lib/module-cluster/ModuleCluster/Define/Block/ModuleOrInstance.rb
53
+ - lib/module-cluster/ModuleCluster/Define/Block/Subclass.rb
50
54
  - lib/module-cluster/ModuleCluster/Define/Block.rb
51
55
  - lib/module-cluster/ModuleCluster/Define/ClassCluster.rb
52
56
  - lib/module-cluster/ModuleCluster/Define/ClassOrInstanceCluster.rb
@@ -76,6 +80,7 @@ files:
76
80
  - spec/ModuleCluster/Define/Block/Instance_spec.rb
77
81
  - spec/ModuleCluster/Define/Block/Module_spec.rb
78
82
  - spec/ModuleCluster/Define/Block/ModuleOrInstance_spec.rb
83
+ - spec/ModuleCluster/Define/Block/Subclass_spec.rb
79
84
  - spec/ModuleCluster/Define/Block_spec.rb
80
85
  - spec/ModuleCluster/Define/ClassCluster_spec.rb
81
86
  - spec/ModuleCluster/Define/ClassOrInstanceCluster_spec.rb