ld 0.2.7 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5e6b6b049c3500199fc6a575bb77171b91fcf29
4
- data.tar.gz: 8af7fdc85064507fe94bd42cba74772af06edb05
3
+ metadata.gz: e89cf241b75524b55030d7380c492ca33997d1a0
4
+ data.tar.gz: 5bf0835e73ca16ac0b6c47d5caa4da5ba632677d
5
5
  SHA512:
6
- metadata.gz: 60aeb848bfb455546fe23799408357a28c88f28a9b06a9d8f2caa6c5915ad2d73b68269a37145caca5ae5d6e2e46bbac6daea83012b3711e868eee3b4f460e9f
7
- data.tar.gz: ea7db3ca6f3901a5dda90a2f4344ef04968cd0f9bcc3271ba1778a81641c7874f04c7ffa1fde4445b0a839e4c0cd33b70a4171f6f315ab56bd4a7fd330b89c9c
6
+ metadata.gz: 9b942469c6091f7d0e7fe839899446f3b07f5a3de8b16d2c2468362f2cdb9ce3ebf0b9e94b9baf1a9e453f312a066c687405197ca83d9f3f048a2ba373d5f5cd
7
+ data.tar.gz: e9c8834ce7d77486ef47c88d6660469b91da4f37b820095c80f231f1c2ff56002db55124f3315d6b35acbf8ff258ecc0da93422ae655544dd802b5b8a856ba40
@@ -23,7 +23,7 @@ class Ld::Controllers
23
23
  controller = find_controller model_name.pluralize
24
24
  if controller
25
25
  controller_lines = controller.lines
26
- controller_methods = controller_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
26
+ controller_methods = controller_lines.map{|l| l.split('def ')[1].chomp if l.match(/def /)}.compact
27
27
  end
28
28
  controller
29
29
  end
@@ -1,9 +1,10 @@
1
1
  class Ld::Models
2
2
  attr_accessor :headings, :rows, :models
3
3
 
4
- def initialize root, tables
4
+ def initialize root, tables, table_hash
5
5
  @root = root
6
6
  @tables = tables
7
+ @table_hash = table_hash
7
8
  parse
8
9
  end
9
10
 
@@ -18,18 +19,20 @@ class Ld::Models
18
19
  methods_full = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
19
20
  methods = methods_full.map{|method_full| method_full.split(' ')[0]}
20
21
  instance = name.camelize.constantize.new
21
- data_count = 0#name.camelize.constantize.count
22
+ data_count = name.camelize.constantize.count
22
23
  fields = instance.attributes.keys
23
24
  relations = get_relations file.lines
24
25
  [
25
- name,name.pluralize,name.camelize,data_count,lines.size,file.path,methods.size,
26
+ name,name.pluralize,@table_hash[name],name.camelize,data_count,lines.size,file.path,methods.size,
26
27
  methods.join(','),fields.join(','),fields.size,
27
28
  relations[:has_many].size,relations[:belongs_to].size,relations[:has_one].size,
28
- relations[:has_many].join(','),relations[:belongs_to].join(','),relations[:has_one].join(',')
29
+ relations[:has_many].join(",\n"),
30
+ relations[:belongs_to].join(",\n"),
31
+ relations[:has_one].join(",\n")
29
32
  ]
30
- }.compact.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序
33
+ }.compact.sort{|a,b| b[0] <=> a[0]} # 按 模型文件行数 排序
31
34
  @models = @rows.map{|arr| arr[0]}.uniq
32
- @headings = ['模型名','表名','类','数据数量','行数','path', '方法数',
35
+ @headings = ['模型名','表名','comment','类','数据数量','行数','path', '方法数',
33
36
  '所有方法', '所有字段','字段数量',
34
37
  'has_many个数','belongs_to个数','has_one个数',
35
38
  'has_many','belongs_to','has_one']
@@ -38,13 +41,20 @@ class Ld::Models
38
41
  def get_relations lines
39
42
  relations = {has_many:[],belongs_to:[],has_one:[]}
40
43
  lines.each do |line|
41
- arr = line.split(' ')
42
- if arr[0] == 'has_many'
43
- relations[:has_many] << arr[1].split(':')[1]
44
- elsif arr[0] == 'belongs_to'
45
- relations[:belongs_to] << arr[1].split(':')[1]
46
- elsif arr[0] == 'has_one'
47
- relations[:has_one] << arr[1].split(':')[1]
44
+ arr = line.split(' ')
45
+ if ['has_many','belongs_to','has_one'].include? arr[0]
46
+ model = arr[1].split(':')[1].split(',')[0]
47
+ china = @table_hash[model.singularize]
48
+ if !china
49
+ if i = arr.index('class_name:')
50
+ if class_name = arr[i+1]
51
+ class_name = class_name.split('"')[1] if class_name.match(/"/)
52
+ class_name = class_name.split("'")[1] if class_name.match(/'/)
53
+ china = @table_hash[class_name.underscore]
54
+ end
55
+ end
56
+ end
57
+ relations[arr[0].to_sym] << "#{model}(#{china})"
48
58
  end
49
59
  end
50
60
  relations
@@ -2,24 +2,99 @@ class Ld::Project
2
2
 
3
3
  attr_accessor :root, :tables, :models, :controllers, :views, :routes
4
4
 
5
- def initialize path = Rails.root.to_s
5
+ def initialize table_hash = {}, path = Rails.root.to_s
6
6
  @root = Ld::File.new path
7
+ @table_hash = table_hash
7
8
  parse_project
8
9
  end
9
10
 
10
11
  def parse_project
11
12
  @tables = Ld::Tables.new @root, nil
12
- @models = Ld::Models.new @root, @tables
13
+ @models = Ld::Models.new @root, @tables, @table_hash
13
14
  @routes = Ld::Routes.new @root, @models
14
15
  @tables = Ld::Tables.new @root, @models
15
16
  @views = Ld::Views.new @root, @models
16
17
  @controllers = Ld::Controllers.new @root, @models
17
18
  end
18
19
 
20
+ def print model_name, type = :relations
21
+ if !@models.models.include? model_name
22
+ puts "不存在 #{model_name}"
23
+ return false
24
+ end
25
+
26
+ title_str = "#{model_name.camelize}(#{@table_hash[model_name]})"
27
+
28
+ case type
29
+ when :fields
30
+ fs = '字段,字段类型,描述,空约束,默认值,精度位数,limit'.split(',')
31
+ indexs = fs.map{|f| @tables.headings.index(f)}.compact
32
+ rows = []
33
+ @tables.rows.select{|a| a[0]==model_name}.each{|arr| rows << indexs.map{|i| arr[i]} }
34
+ puts Terminal::Table.new(
35
+ :title => "#{title_str}:字段解释",
36
+ :headings => fs,
37
+ :rows => rows
38
+ )
39
+ when :relations
40
+ fs = 'has_many,belongs_to,has_one'.split(',')
41
+ indexs = fs.map{|f| @models.headings.index(f)}.compact
42
+ rows = []
43
+ @models.rows.select{|a| a[0]==model_name}.each{|arr|
44
+ rows << indexs.map{|i| arr[i]}
45
+ }
46
+ puts Terminal::Table.new(
47
+ :title => "#{title_str}:关联关系",
48
+ :headings => fs,
49
+ :rows => rows
50
+ )
51
+ when :routes
52
+ fs = '控制器,action,请求类型,URI,帮助方法'.split(',')
53
+ indexs = fs.map{|f| @routes.headings.index(f)}.compact
54
+ rows = []
55
+ @routes.rows.select{|a| a[0]==model_name}.each{|arr| rows << indexs.map{|i| arr[i]} }
56
+ puts Terminal::Table.new(
57
+ :title => "#{title_str}:路由",
58
+ :headings => fs,
59
+ :rows => rows
60
+ )
61
+ when :views
62
+ fs = '文件夹名,行数,文件名,path'.split(',')
63
+ indexs = fs.map{|f| @views.headings.index(f)}.compact
64
+ rows = []
65
+ @views.rows.select{|a| a[0]==model_name}.each{|arr| rows << indexs.map{|i| arr[i]} }
66
+ puts Terminal::Table.new(
67
+ :title => "#{title_str}:视图",
68
+ :headings => fs,
69
+ :rows => rows
70
+ )
71
+ when :controllers
72
+ fs = 'action个数,文件行数,所有action'.split(',')
73
+ indexs = fs.map{|f| @controllers.headings.index(f)}.compact
74
+ rows = []
75
+ @controllers.rows.select{|a| a[0]==model_name}.each{|arr| rows << indexs.map{|i| arr[i]} }
76
+ puts Terminal::Table.new(
77
+ :title => "#{title_str}:控制器",
78
+ :headings => fs,
79
+ :rows => rows
80
+ )
81
+ end
82
+
83
+ true
84
+ end
85
+
86
+ def delete_rows_index
87
+ @routes.rows.delete_at 0
88
+ @tables.rows.delete_at 0
89
+ @models.rows.delete_at 0
90
+ @views.rows.delete_at 0
91
+ @controllers.rows.delete_at 0
92
+ end
93
+
19
94
  def to_xls path = "#{@root.path}/project.xls"
20
95
  Ld::Excel.create path do |excel|
21
- # sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
22
96
  excel.write_sheet 'routes' do |sheet|
97
+ sheet.set_format({color: :black, font_size: 18, font: '微软雅黑'})
23
98
  sheet.set_headings @routes.headings
24
99
  sheet.set_rows @routes.rows
25
100
  end
@@ -40,10 +115,13 @@ class Ld::Project
40
115
  sheet.set_rows @controllers.rows
41
116
  end
42
117
  end
118
+ #delete_rows_index
43
119
  end
44
120
 
45
121
  def add_bug
46
122
 
47
123
  end
48
124
 
125
+
126
+
49
127
  end
data/lib/ld/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ld
2
- VERSION = "0.2.7"
2
+ VERSION = "0.2.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Dong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: terminal-table