class_dependencies 0.3.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,10 @@ this as follows :
13
13
  =>[:c, :b, :a]
14
14
  DependsOn.ordered_dependent_classes
15
15
  =>[C, B, A]
16
+ DependsOn.descendants
17
+ =>[:a, :b, :c]
18
+ DependsOn.descendant_classes
19
+ =>[A, B, C]
16
20
 
17
21
  == Install
18
22
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
@@ -17,6 +17,10 @@ require 'inflector'
17
17
  # => [:c, :b, :a]
18
18
  # SomeDep.ordered_dependent_classes
19
19
  # => [C, B, A]
20
+ # SomeDep.descendants
21
+ # => [:a, :b, :c]
22
+ # SomeDep.descendant_classes
23
+ # => [A, B, C]
20
24
  #
21
25
  # class AnotherDep ; include ClassDependencies ; end
22
26
  # class D < Top ; another_dep :e ; end
@@ -36,7 +40,12 @@ require 'inflector'
36
40
  module ClassDependencies
37
41
  class TSortHash < Hash
38
42
  include TSort
39
- alias tsort_each_node each_key
43
+ def initialize(mod)
44
+ @mod = mod
45
+ end
46
+ def tsort_each_node(&block)
47
+ @mod.descendants.each(&block)
48
+ end
40
49
  def tsort_each_child(node,&block)
41
50
  fetch(node,[]).each(&block)
42
51
  end
@@ -87,7 +96,7 @@ module ClassDependencies
87
96
  end
88
97
  # generate the dependency list value and the descendants value accessors
89
98
  # on first include : they return a closed over value
90
- dependencies = TSortHash.new
99
+ dependencies = TSortHash.new(mod)
91
100
  descendants = []
92
101
  mc.send(:define_method, :class_dependencies){dependencies} if ! mc.instance_methods.include?("class_dependencies")
93
102
  mc.send(:define_method, :descendants){descendants} if ! mc.instance_methods.include?("descendants")
@@ -114,4 +114,19 @@ describe "ClassDependencies" do
114
114
  WithInheritedMethod.count.should == 2
115
115
  end
116
116
 
117
+ module Foo
118
+ include ClassDependencies
119
+ end
120
+
121
+ class K
122
+ include Foo
123
+ end
124
+
125
+ class L
126
+ include Foo
127
+ end
128
+
129
+ it "should return all dependencies even without relationships" do
130
+ Foo.ordered_dependencies.to_set.should == Set.new([:k,:l])
131
+ end
117
132
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
7
  - 4
9
- version: 0.3.4
8
+ - 0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - mccraig mccraig of the clan mccraig
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +00:00
17
+ date: 2010-03-25 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency