class_dependencies 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/class_dependencies.rb +12 -11
  3. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,5 +1,6 @@
1
1
  require 'set'
2
- require 'inflector.rb'
2
+ require 'tsort'
3
+ require 'inflector'
3
4
 
4
5
  # include Sonar::ClassDependencies onto a Module or Class
5
6
  # then include that Module, or inherit from that Class,
@@ -34,6 +35,14 @@ require 'inflector.rb'
34
35
 
35
36
  module Sonar
36
37
  module ClassDependencies
38
+ class TSortHash < Hash
39
+ include TSort
40
+ alias tsort_each_node each_key
41
+ def tsort_each_child(node,&block)
42
+ fetch(node,[]).each(&block)
43
+ end
44
+ end
45
+
37
46
  module ClassName
38
47
  def class_to_sym(klass)
39
48
  klass.to_s.underscore.to_sym
@@ -79,7 +88,7 @@ module Sonar
79
88
  end
80
89
  # generate the dependency list value and the descendants value accessors
81
90
  # on first include : they return a closed over value
82
- dependencies = {}
91
+ dependencies = TSortHash.new
83
92
  descendants = []
84
93
  mc.send(:define_method, :class_dependencies){dependencies}
85
94
  mc.send(:define_method, :descendants){descendants}
@@ -117,15 +126,7 @@ module Sonar
117
126
  end
118
127
 
119
128
  def ordered_dependencies
120
- descendants.sort do |a,b|
121
- if all_dependencies_of(a).include?(b)
122
- +1
123
- elsif all_dependencies_of(b).include?(a)
124
- -1
125
- else
126
- 0
127
- end
128
- end
129
+ class_dependencies.tsort
129
130
  end
130
131
 
131
132
  def ordered_dependent_classes
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
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-23 00:00:00 +00:00
17
+ date: 2010-03-24 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency