ruby_uml_class 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +45 -37
- data/bin/start_ruby_uml_class.rb +0 -0
- data/bin/start_ruby_uml_class.rbw +0 -0
- data/lib/config/setting.json +19 -19
- data/lib/config.ru +107 -107
- data/lib/create_uml_class.rb +322 -297
- data/lib/history/history.json +2 -2
- data/lib/js/main.js +463 -463
- data/lib/ruby_uml_class/version.rb +5 -5
- data/lib/start.rb +0 -0
- metadata +6 -6
data/lib/create_uml_class.rb
CHANGED
|
@@ -1,297 +1,322 @@
|
|
|
1
|
-
require "tempfile"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
:
|
|
6
|
-
:
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
o_list.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
o_list.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
o_list.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
#
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
end
|
|
1
|
+
require "tempfile"
|
|
2
|
+
require "facter"
|
|
3
|
+
|
|
4
|
+
CStruct = Struct.new(:type,
|
|
5
|
+
:name,
|
|
6
|
+
:block_count,
|
|
7
|
+
:var_list,
|
|
8
|
+
:method_list,
|
|
9
|
+
:inherit_list,
|
|
10
|
+
:composition_list)
|
|
11
|
+
|
|
12
|
+
def get_rufo_path
|
|
13
|
+
ENV["PATH"].split(";").each do |path|
|
|
14
|
+
rufo_path = "#{path}\\rufo"
|
|
15
|
+
if File.exists? rufo_path
|
|
16
|
+
return rufo_path
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
return ""
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def print_uml(out, out_list)
|
|
23
|
+
out_list.each do |o_list|
|
|
24
|
+
if o_list.type == :class_start
|
|
25
|
+
# nop
|
|
26
|
+
elsif o_list.type == :module_start
|
|
27
|
+
out.push "namespace #{o_list.name} {"
|
|
28
|
+
elsif o_list.type == :class_end
|
|
29
|
+
pp o_list if o_list.name == ""
|
|
30
|
+
out.push "class #{o_list.name} {"
|
|
31
|
+
# インスタンス変数の出力
|
|
32
|
+
o_list.var_list.uniq.each do |iv|
|
|
33
|
+
out.push iv
|
|
34
|
+
end
|
|
35
|
+
# メソッドの出力
|
|
36
|
+
o_list.method_list.each do |ml|
|
|
37
|
+
out.push ml
|
|
38
|
+
end
|
|
39
|
+
out.push "}"
|
|
40
|
+
# 継承リストの出力
|
|
41
|
+
o_list.inherit_list.each do |ih|
|
|
42
|
+
out.push "#{o_list.name} --|> #{ih}"
|
|
43
|
+
end
|
|
44
|
+
# compo
|
|
45
|
+
o_list.composition_list.uniq.each do |co|
|
|
46
|
+
out.push "#{o_list.name} *-- #{co}"
|
|
47
|
+
end
|
|
48
|
+
elsif o_list.type == :module_end
|
|
49
|
+
# インスタンス変数がある場合はモジュール名と同じクラスを定義
|
|
50
|
+
if o_list.var_list.size != 0 or
|
|
51
|
+
o_list.method_list.size != 0 or
|
|
52
|
+
o_list.inherit_list.size != 0 or
|
|
53
|
+
o_list.composition_list.size != 0
|
|
54
|
+
pp o_list if o_list.name == ""
|
|
55
|
+
out.push "class #{o_list.name} {"
|
|
56
|
+
# インスタンス変数の出力
|
|
57
|
+
o_list.var_list.uniq.each do |iv|
|
|
58
|
+
out.push iv
|
|
59
|
+
end
|
|
60
|
+
# メソッドの出力
|
|
61
|
+
o_list.method_list.each do |ml|
|
|
62
|
+
out.push ml
|
|
63
|
+
end
|
|
64
|
+
out.push "}"
|
|
65
|
+
# 継承リストの出力
|
|
66
|
+
o_list.inherit_list.each do |ih|
|
|
67
|
+
out.push "#{o_list.name} --|> #{ih}"
|
|
68
|
+
end
|
|
69
|
+
# compo
|
|
70
|
+
o_list.composition_list.uniq.each do |co|
|
|
71
|
+
out.push "#{o_list.name} *-- #{co}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
out.push "}"
|
|
75
|
+
else
|
|
76
|
+
# error
|
|
77
|
+
puts "error!"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
return out
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def delete_here_doc(buf)
|
|
84
|
+
new_buf = []
|
|
85
|
+
here_doc = false
|
|
86
|
+
here_word = ""
|
|
87
|
+
buf.each_line do |line|
|
|
88
|
+
if line =~ /(<<|<<~|<<-)[A-Z]+/
|
|
89
|
+
here_doc = true
|
|
90
|
+
here_word = line.match(/(<<|<<~|<<-)[A-Z]+/).to_s.gsub(/[<~-]/, "")
|
|
91
|
+
end
|
|
92
|
+
if here_word != "" and line =~ Regexp.new("^\s*#{here_word}$")
|
|
93
|
+
here_word = ""
|
|
94
|
+
here_doc = false
|
|
95
|
+
pp line
|
|
96
|
+
end
|
|
97
|
+
if here_doc == false
|
|
98
|
+
new_buf.push line
|
|
99
|
+
else
|
|
100
|
+
pp line
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
return new_buf.join("")
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def create_uml_class(in_dir, out_file)
|
|
107
|
+
out = []
|
|
108
|
+
out.push "@startuml"
|
|
109
|
+
|
|
110
|
+
puts "in_dir = #{in_dir}"
|
|
111
|
+
main_composition_list = []
|
|
112
|
+
main_method_list = []
|
|
113
|
+
global_var = []
|
|
114
|
+
|
|
115
|
+
Dir.glob("#{in_dir}/**/*.{rb,ru}") do |f|
|
|
116
|
+
puts f
|
|
117
|
+
buf = ""
|
|
118
|
+
Tempfile.create("rufo") do |tmp_file|
|
|
119
|
+
FileUtils.cp(f, tmp_file.path)
|
|
120
|
+
kernel = Facter.value(:kernel)
|
|
121
|
+
if kernel == "windows"
|
|
122
|
+
open("|rubyw #{get_rufo_path} #{tmp_file.path}") do |f|
|
|
123
|
+
if f.read =~ /error/
|
|
124
|
+
puts "rufo error #{f}"
|
|
125
|
+
return
|
|
126
|
+
else
|
|
127
|
+
buf = File.binread tmp_file.path
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
else
|
|
131
|
+
open("|rufo #{tmp_file.path}") do |f|
|
|
132
|
+
if f.read =~ /error/
|
|
133
|
+
puts "rufo error #{f}"
|
|
134
|
+
return
|
|
135
|
+
else
|
|
136
|
+
buf = File.binread tmp_file.path
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# コメント削除
|
|
143
|
+
buf.gsub!(/(([\/\"\'].*?[\/\"\'])|([^\/\"\'\)\s]*#.+?$))/) do |m|
|
|
144
|
+
if m[0] == "#" and m[0] != "{"
|
|
145
|
+
#puts "comment #{m}"
|
|
146
|
+
# コメント
|
|
147
|
+
""
|
|
148
|
+
else
|
|
149
|
+
#puts "not comment #{m}"
|
|
150
|
+
# コメント以外
|
|
151
|
+
m
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
# ヒアドキュメント削除
|
|
155
|
+
buf = delete_here_doc(buf)
|
|
156
|
+
|
|
157
|
+
out_list = []
|
|
158
|
+
cstruct_list = []
|
|
159
|
+
block_count = 0
|
|
160
|
+
method_type = :public
|
|
161
|
+
class_name = ""
|
|
162
|
+
# ソースを解析
|
|
163
|
+
buf.each_line do |line|
|
|
164
|
+
next if line =~ /^[\r\n]*$/ # 空行は対象外
|
|
165
|
+
|
|
166
|
+
# ブロックの開始/終了
|
|
167
|
+
indent_num = line.match(/^[ ]+/).to_s.size / 2
|
|
168
|
+
if block_count == indent_num
|
|
169
|
+
# 変化なし
|
|
170
|
+
elsif block_count > indent_num
|
|
171
|
+
# ブロックの終了
|
|
172
|
+
block_count = indent_num
|
|
173
|
+
else
|
|
174
|
+
# ブロックの開始
|
|
175
|
+
block_count = indent_num
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
#line.gsub!(/\".+\"/, "\"delete_string\"") # 文字列を削除
|
|
179
|
+
if line =~ /^\s*class\s/
|
|
180
|
+
unless line =~ /<</ # 特異クラスではない
|
|
181
|
+
work = line.gsub(/class\s/, "")
|
|
182
|
+
class_name = work.split("<")[0].to_s.chomp.match(/[A-Z][A-Za-z0-9_:]+/).to_s
|
|
183
|
+
base_name = work.split("<")[1].to_s.chomp.match(/[A-Z][A-Za-z0-9_:]+/).to_s
|
|
184
|
+
class_name.gsub!(/::/, ".")
|
|
185
|
+
class_name.gsub!(/;/, "")
|
|
186
|
+
if out_list.size != 0 and out_list[-1].type == :class_start # classが連続している
|
|
187
|
+
class_name = out_list[-1].name + "." + class_name
|
|
188
|
+
out_list[-1].name = class_name
|
|
189
|
+
cstruct_list[-1].name = class_name
|
|
190
|
+
else
|
|
191
|
+
out_list.push CStruct.new(:class_start, class_name, block_count, [], [], [], [])
|
|
192
|
+
cstruct_list.push CStruct.new(:class_end, class_name, block_count, [], [], [], [])
|
|
193
|
+
end
|
|
194
|
+
#pp line if class_name == ""
|
|
195
|
+
if base_name != ""
|
|
196
|
+
#base_name.gsub!(/::/, ".")
|
|
197
|
+
cstruct_list[-1].inherit_list.push base_name
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
next unless line =~ /end\s*$/ # 1行で終了しない場合
|
|
201
|
+
elsif line =~ /^\s*module\s/
|
|
202
|
+
module_name = line.split(" ")[1].to_s.chomp
|
|
203
|
+
module_name.gsub!(/^[:]+/, "")
|
|
204
|
+
module_name.gsub!(/::/, ".")
|
|
205
|
+
module_name.gsub!(/;/, "")
|
|
206
|
+
out_list.push CStruct.new(:module_start, module_name, block_count, [], [], [], [])
|
|
207
|
+
cstruct_list.push CStruct.new(:module_end, module_name, block_count, [], [], [], [])
|
|
208
|
+
next unless line =~ /end\s*$/ # 1行で終了しない場合
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
if line =~ /^\s*private$/
|
|
212
|
+
method_type = :private
|
|
213
|
+
elsif line =~ /^\s*protected$/
|
|
214
|
+
method_type = :protected
|
|
215
|
+
elsif line =~ /^\s*public$/
|
|
216
|
+
method_type = :public
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
if line =~ /^\s*def\s/
|
|
220
|
+
# 関数名を取り出す
|
|
221
|
+
method = line.chomp.gsub(/\s*def\s*/, "")
|
|
222
|
+
unless method =~ /\(/
|
|
223
|
+
# 関数名にカッコをつける
|
|
224
|
+
sp = method.split(" ")
|
|
225
|
+
if sp.size > 1
|
|
226
|
+
method = sp[0].to_s + "(" + sp[1..-1].to_s + ")"
|
|
227
|
+
else
|
|
228
|
+
method = method + "()"
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
if cstruct_list.size != 0
|
|
232
|
+
method_list = cstruct_list[-1].method_list
|
|
233
|
+
case method_type
|
|
234
|
+
when :public
|
|
235
|
+
method_list.push "+ #{method}"
|
|
236
|
+
when :private
|
|
237
|
+
method_list.push "- #{method}"
|
|
238
|
+
when :protected
|
|
239
|
+
method_list.push "# #{method}"
|
|
240
|
+
end
|
|
241
|
+
else
|
|
242
|
+
main_method_list.push "+ #{method}"
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
# composition_list
|
|
247
|
+
line.match(/(([\/\"\')].*?\.new.*?[\/\"\'])|(?![\/\"\'])([a-zA-Z0-9_]+\.new))/) do |m|
|
|
248
|
+
if m.to_s[0] != "/" and m.to_s[0] != "\"" and m.to_s[0] != "'"
|
|
249
|
+
name = m.to_s.gsub(/\.new/, "").match(/[A-Z][A-Za-z0-9_]+/).to_s
|
|
250
|
+
if name != ""
|
|
251
|
+
if cstruct_list.size != 0
|
|
252
|
+
cstruct_list[-1].composition_list.push name
|
|
253
|
+
else
|
|
254
|
+
main_composition_list.push "main *-- #{name}"
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# インスタンス変数
|
|
261
|
+
if line =~ /\s*@\S+/
|
|
262
|
+
if cstruct_list.size != 0
|
|
263
|
+
line.match(/@[a-zA-Z0-9_]+/) { |m|
|
|
264
|
+
instance_var = cstruct_list[-1].var_list
|
|
265
|
+
val = m.to_s.gsub(/@/, "")
|
|
266
|
+
case method_type
|
|
267
|
+
when :public
|
|
268
|
+
instance_var.push "+ #{val}"
|
|
269
|
+
when :private
|
|
270
|
+
instance_var.push "- #{val}"
|
|
271
|
+
when :protected
|
|
272
|
+
instance_var.push "# #{val}"
|
|
273
|
+
end
|
|
274
|
+
}
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
# 外部変数
|
|
279
|
+
line.match(/\$[a-zA-Z0-9_]+/) { |m|
|
|
280
|
+
global_var.push "+ #{m.to_s}"
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
# クラスの終了
|
|
284
|
+
if cstruct_list.size != 0
|
|
285
|
+
if block_count == cstruct_list[-1].block_count # block_countが一致
|
|
286
|
+
#puts "end of #{cstruct_list[-1].name}"
|
|
287
|
+
out_list.push cstruct_list[-1]
|
|
288
|
+
cstruct_list.slice!(-1) # 最後の要素を削除
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
#puts "#{block_count} #{line.chomp}"
|
|
292
|
+
end
|
|
293
|
+
if block_count != 0
|
|
294
|
+
# エラー
|
|
295
|
+
puts f
|
|
296
|
+
return ""
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
# UMLの出力
|
|
300
|
+
out = print_uml(out, out_list)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
if main_method_list.size != 0 or
|
|
304
|
+
main_composition_list.size != 0 or
|
|
305
|
+
main_method_list.size != 0
|
|
306
|
+
out.push "class main {"
|
|
307
|
+
main_method_list.each do |mml|
|
|
308
|
+
out.push mml
|
|
309
|
+
end
|
|
310
|
+
# グローバル変数の出力
|
|
311
|
+
global_var.uniq.each do |gv|
|
|
312
|
+
out.push gv
|
|
313
|
+
end
|
|
314
|
+
out.push "}"
|
|
315
|
+
main_composition_list.uniq.each do |mcl|
|
|
316
|
+
out.push mcl
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
out.push "@enduml"
|
|
321
|
+
return out.join("\n")
|
|
322
|
+
end
|
data/lib/history/history.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
[
|
|
2
|
-
|
|
1
|
+
[
|
|
2
|
+
|
|
3
3
|
]
|