11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ld/project/models.rb', line 11
def parse
rows = []
model_files = @root.find('app/models').search_regexp(/.rb$/).map{|m|
m if @tables.tables.include?(m.name.split('.')[0].pluralize)
}.compact
@rows = model_files.map{ |file|
name = file.name.split('.')[0]
lines = file.lines
methods_full = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
methods = methods_full.map{|method_full| method_full.split(' ')[0]}
instance = name.camelize.constantize.new
data_count = nil fields = instance.attributes.keys
relations = get_relations file.lines
[
name,name.pluralize,@table_hash[name],name.camelize,data_count,lines.size,file.path,methods.size,
methods.join(','),fields.join(','),fields.size,
relations[:has_many].size,relations[:belongs_to].size,relations[:has_one].size,
relations[:has_many].join(",\n"),
relations[:belongs_to].join(",\n"),
relations[:has_one].join(",\n")
]
}.compact.sort{|a,b| b[0] <=> a[0]} @models = @rows.map{|arr| arr[0]}.uniq
@headings = ['模型名','表名','comment','类','数据数量','行数','path', '方法数',
'所有方法', '所有字段','字段数量',
'has_many个数','belongs_to个数','has_one个数',
'has_many','belongs_to','has_one']
end
|