ruby-codegraph 0.0.2 → 0.0.3
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.
- data/lib/codegraph/inheritance.rb +13 -11
- data/lib/codegraph/inheritance_processor.rb +97 -0
- data/lib/codegraph/version.rb +1 -1
- metadata +19 -2
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'ruby_parser'
|
2
|
+
require File.expand_path('../inheritance_processor', __FILE__)
|
3
|
+
|
1
4
|
module CodeGraph
|
2
5
|
|
3
6
|
class Inheritance
|
@@ -11,6 +14,7 @@ module CodeGraph
|
|
11
14
|
@nodes = {}
|
12
15
|
@edges = {}
|
13
16
|
|
17
|
+
@processor = InheritanceProcessor.new
|
14
18
|
@g = GraphViz.new(@options[:graph_name], graphviz_options)
|
15
19
|
end
|
16
20
|
|
@@ -40,18 +44,16 @@ module CodeGraph
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def directory_scan
|
43
|
-
Dir["#{@dir}/**/*.rb"].each
|
44
|
-
|
47
|
+
Dir["#{@dir}/**/*.rb"].each do |rb|
|
48
|
+
sexp = RubyParser.new.parse File.read(rb)
|
49
|
+
@processor.process(sexp)
|
50
|
+
end
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
if parent
|
52
|
-
add_node(parent)
|
53
|
-
add_edge(klass, parent)
|
54
|
-
end
|
52
|
+
@processor.classes.each do |klass, parent|
|
53
|
+
add_node(klass)
|
54
|
+
if parent
|
55
|
+
add_node(parent)
|
56
|
+
add_edge(klass, parent)
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'sexp_processor'
|
2
|
+
|
3
|
+
module CodeGraph
|
4
|
+
class InheritanceProcessor < SexpProcessor
|
5
|
+
attr :classes
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
self.strict = false
|
10
|
+
|
11
|
+
@scopes = []
|
12
|
+
@classes = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
alias :_process :process
|
16
|
+
def process(exp)
|
17
|
+
_process(exp)
|
18
|
+
fix_parents
|
19
|
+
classes
|
20
|
+
end
|
21
|
+
|
22
|
+
def fix_parents
|
23
|
+
@classes.each do |klass, parent|
|
24
|
+
@classes[klass] = best_fit_name(parent)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def best_fit_name(parent)
|
29
|
+
loop do
|
30
|
+
return parent if @classes.keys.include?(parent)
|
31
|
+
return parent if parent !~ /::/
|
32
|
+
parent = parent.split('::', 2)[1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def process_const(exp)
|
37
|
+
name = atom(exp[1])
|
38
|
+
exp.clear
|
39
|
+
s(name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def process_colon2(exp)
|
43
|
+
name = [atom(exp[1]), atom(exp[2])].join('::')
|
44
|
+
exp.clear
|
45
|
+
s(name)
|
46
|
+
end
|
47
|
+
|
48
|
+
def process_class(exp)
|
49
|
+
directive, klass, parent = exp[0..2]
|
50
|
+
extra = exp[3..-1]
|
51
|
+
exp.clear
|
52
|
+
|
53
|
+
add_class atom(klass), atom(parent)
|
54
|
+
|
55
|
+
@scopes.push klass
|
56
|
+
processed = [directive, klass, parent].concat(extra.map{|e| _process(e)})
|
57
|
+
@scopes.pop
|
58
|
+
|
59
|
+
s(*processed)
|
60
|
+
end
|
61
|
+
|
62
|
+
def process_module(exp)
|
63
|
+
directive, klass = exp[0..1]
|
64
|
+
extra = exp[2..-1]
|
65
|
+
exp.clear
|
66
|
+
|
67
|
+
@scopes.push klass
|
68
|
+
processed = [directive, klass].concat(extra.map{|e| _process(e)})
|
69
|
+
@scopes.pop
|
70
|
+
|
71
|
+
s(*processed)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def add_class(klass, parent)
|
77
|
+
@classes[full_name(klass)] = full_name(parent)
|
78
|
+
end
|
79
|
+
|
80
|
+
def full_name(exp)
|
81
|
+
return unless exp
|
82
|
+
return exp[1].to_s if exp[0] == :colon3
|
83
|
+
|
84
|
+
scoped_name = @scopes + [exp]
|
85
|
+
scoped_name.join('::')
|
86
|
+
end
|
87
|
+
|
88
|
+
def atom(exp)
|
89
|
+
if exp.is_a?(Sexp)
|
90
|
+
_process(exp)
|
91
|
+
else
|
92
|
+
exp
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
data/lib/codegraph/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-codegraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby-graphviz
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ruby_parser
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.0
|
30
46
|
description: Use codegraph to generate all kinds of graphviz graphs for you code,
|
31
47
|
to visualize things like class hierarchy.
|
32
48
|
email:
|
@@ -39,6 +55,7 @@ files:
|
|
39
55
|
- lib/codegraph.rb
|
40
56
|
- lib/codegraph/version.rb
|
41
57
|
- lib/codegraph/inheritance.rb
|
58
|
+
- lib/codegraph/inheritance_processor.rb
|
42
59
|
- bin/codegraph
|
43
60
|
- LICENSE
|
44
61
|
- README.markdown
|