ruby-codegraph 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/codegraph/inheritance_processor.rb +20 -22
- data/lib/codegraph/version.rb +1 -1
- metadata +1 -1
@@ -2,7 +2,6 @@ require 'sexp_processor'
|
|
2
2
|
|
3
3
|
module CodeGraph
|
4
4
|
class InheritanceProcessor < SexpProcessor
|
5
|
-
attr :classes
|
6
5
|
|
7
6
|
def initialize
|
8
7
|
super
|
@@ -12,25 +11,9 @@ module CodeGraph
|
|
12
11
|
@classes = {}
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
def process(exp)
|
17
|
-
_process(exp)
|
14
|
+
def classes
|
18
15
|
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
|
16
|
+
@classes
|
34
17
|
end
|
35
18
|
|
36
19
|
def process_const(exp)
|
@@ -53,7 +36,7 @@ module CodeGraph
|
|
53
36
|
add_class atom(klass), atom(parent)
|
54
37
|
|
55
38
|
@scopes.push klass
|
56
|
-
processed = [directive, klass, parent].concat(extra.map{|e|
|
39
|
+
processed = [directive, klass, parent].concat(extra.map{|e| process(e)})
|
57
40
|
@scopes.pop
|
58
41
|
|
59
42
|
s(*processed)
|
@@ -65,7 +48,7 @@ module CodeGraph
|
|
65
48
|
exp.clear
|
66
49
|
|
67
50
|
@scopes.push klass
|
68
|
-
processed = [directive, klass].concat(extra.map{|e|
|
51
|
+
processed = [directive, klass].concat(extra.map{|e| process(e)})
|
69
52
|
@scopes.pop
|
70
53
|
|
71
54
|
s(*processed)
|
@@ -87,11 +70,26 @@ module CodeGraph
|
|
87
70
|
|
88
71
|
def atom(exp)
|
89
72
|
if exp.is_a?(Sexp)
|
90
|
-
|
73
|
+
process(exp)
|
91
74
|
else
|
92
75
|
exp
|
93
76
|
end
|
94
77
|
end
|
95
78
|
|
79
|
+
def fix_parents
|
80
|
+
@classes.each do |klass, parent|
|
81
|
+
@classes[klass] = best_fit_name(parent)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def best_fit_name(parent)
|
86
|
+
orig = parent
|
87
|
+
loop do
|
88
|
+
return parent if @classes.keys.include?(parent)
|
89
|
+
return orig if parent !~ /::/
|
90
|
+
parent = parent.split('::', 2)[1]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
96
94
|
end
|
97
95
|
end
|
data/lib/codegraph/version.rb
CHANGED