ld 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -32
- data/lib/ld/project/models.rb +26 -3
- data/lib/ld/project/project.rb +3 -5
- data/lib/ld/project/routes.rb +13 -12
- data/lib/ld/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5e6b6b049c3500199fc6a575bb77171b91fcf29
|
4
|
+
data.tar.gz: 8af7fdc85064507fe94bd42cba74772af06edb05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60aeb848bfb455546fe23799408357a28c88f28a9b06a9d8f2caa6c5915ad2d73b68269a37145caca5ae5d6e2e46bbac6daea83012b3711e868eee3b4f460e9f
|
7
|
+
data.tar.gz: ea7db3ca6f3901a5dda90a2f4344ef04968cd0f9bcc3271ba1778a81641c7874f04c7ffa1fde4445b0a839e4c0cd33b70a4171f6f315ab56bd4a7fd330b89c9c
|
data/README.md
CHANGED
@@ -8,25 +8,6 @@ Basically has the following Class.
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
module Ld
|
11
|
-
class Excel
|
12
|
-
end
|
13
|
-
class Sheets
|
14
|
-
end
|
15
|
-
|
16
|
-
class File
|
17
|
-
end
|
18
|
-
class Files
|
19
|
-
end
|
20
|
-
|
21
|
-
class Print
|
22
|
-
end
|
23
|
-
|
24
|
-
module Project
|
25
|
-
class Structure
|
26
|
-
end
|
27
|
-
class Parse
|
28
|
-
end
|
29
|
-
end
|
30
11
|
end
|
31
12
|
```
|
32
13
|
## Introduction to the
|
@@ -64,29 +45,37 @@ First , into the console:
|
|
64
45
|
Then, can do this:
|
65
46
|
|
66
47
|
```ruby
|
67
|
-
#
|
68
|
-
Ld::
|
48
|
+
# Project details to /project.xls 查看项目详情,会生成xls文件,在: /project.xls
|
49
|
+
Ld::Project.new.to_xls
|
50
|
+
|
51
|
+
# Read xls
|
52
|
+
Ld::Excel.open('project.xls').read('models?a1:j100-f,h,i')
|
53
|
+
Ld::Excel.open('project.xls').read('tables?a1:i300')
|
69
54
|
|
70
55
|
# Create xls, Need to change the file path to your own, and then run
|
71
|
-
Ld::Excel.create '
|
56
|
+
Ld::Excel.create 'excel_test.xls' do |excel|
|
72
57
|
excel.write_sheet 'sheet1' do |sheet|
|
73
58
|
sheet.set_format({color: :red, font_size: 11, font: '宋体'})
|
74
59
|
sheet.set_headings ['title1','title2','title3']
|
75
60
|
sheet.set_point 'a1'
|
76
|
-
|
77
|
-
|
78
|
-
|
61
|
+
sheet.set_rows [
|
62
|
+
[1,2,3,4,5],
|
63
|
+
[1,2,3,4],
|
64
|
+
[1,2,3],
|
65
|
+
[1,2],
|
66
|
+
[1],
|
67
|
+
]
|
79
68
|
end
|
80
69
|
end
|
70
|
+
Ld::Excel.open('excel_test.xls').read('sheet1?a1:g6')
|
81
71
|
|
82
|
-
#
|
83
|
-
Ld::
|
84
|
-
|
85
|
-
# Read Dir
|
86
|
-
Ld::File.open_dir('dir_path').children.each{|f| puts f.path}
|
72
|
+
# Print model, Need to change the User model to exist, to run again
|
73
|
+
Ld::Print.p User.first(10), 'id ,name, created_at'
|
87
74
|
|
88
|
-
#
|
89
|
-
Ld::
|
75
|
+
# Read dir or file
|
76
|
+
Ld::File.new('Gemfile').lines.each{|l| puts l}
|
77
|
+
Ld::File.new('app').models.children.each{|f| puts f.name}
|
78
|
+
Ld::File.new('app').views.search_files(/.html/).each{|f| puts "#{f.father.name} : #{f.name}"}
|
90
79
|
|
91
80
|
```
|
92
81
|
|
data/lib/ld/project/models.rb
CHANGED
@@ -18,13 +18,36 @@ class Ld::Models
|
|
18
18
|
methods_full = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
|
19
19
|
methods = methods_full.map{|method_full| method_full.split(' ')[0]}
|
20
20
|
instance = name.camelize.constantize.new
|
21
|
-
data_count = name.camelize.constantize.count
|
21
|
+
data_count = 0#name.camelize.constantize.count
|
22
22
|
fields = instance.attributes.keys
|
23
|
-
|
23
|
+
relations = get_relations file.lines
|
24
|
+
[
|
25
|
+
name,name.pluralize,name.camelize,data_count,lines.size,file.path,methods.size,
|
26
|
+
methods.join(','),fields.join(','),fields.size,
|
27
|
+
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
|
+
]
|
24
30
|
}.compact.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序
|
25
31
|
@models = @rows.map{|arr| arr[0]}.uniq
|
26
|
-
@headings = ['模型名','表名','类','数据数量','行数','path', '方法数',
|
32
|
+
@headings = ['模型名','表名','类','数据数量','行数','path', '方法数',
|
33
|
+
'所有方法', '所有字段','字段数量',
|
34
|
+
'has_many个数','belongs_to个数','has_one个数',
|
35
|
+
'has_many','belongs_to','has_one']
|
27
36
|
end
|
28
37
|
|
38
|
+
def get_relations lines
|
39
|
+
relations = {has_many:[],belongs_to:[],has_one:[]}
|
40
|
+
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]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
relations
|
51
|
+
end
|
29
52
|
|
30
53
|
end
|
data/lib/ld/project/project.rb
CHANGED
@@ -4,19 +4,19 @@ class Ld::Project
|
|
4
4
|
|
5
5
|
def initialize path = Rails.root.to_s
|
6
6
|
@root = Ld::File.new path
|
7
|
+
parse_project
|
7
8
|
end
|
8
9
|
|
9
10
|
def parse_project
|
10
|
-
@routes = Ld::Routes.new @root
|
11
11
|
@tables = Ld::Tables.new @root, nil
|
12
12
|
@models = Ld::Models.new @root, @tables
|
13
|
+
@routes = Ld::Routes.new @root, @models
|
13
14
|
@tables = Ld::Tables.new @root, @models
|
14
15
|
@views = Ld::Views.new @root, @models
|
15
16
|
@controllers = Ld::Controllers.new @root, @models
|
16
17
|
end
|
17
18
|
|
18
19
|
def to_xls path = "#{@root.path}/project.xls"
|
19
|
-
parse_project
|
20
20
|
Ld::Excel.create path do |excel|
|
21
21
|
# sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
|
22
22
|
excel.write_sheet 'routes' do |sheet|
|
@@ -42,10 +42,8 @@ class Ld::Project
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def add_bug
|
45
46
|
|
46
|
-
def camelize name
|
47
|
-
name.camelize
|
48
47
|
end
|
49
48
|
|
50
|
-
|
51
49
|
end
|
data/lib/ld/project/routes.rb
CHANGED
@@ -2,29 +2,30 @@ class Ld::Routes
|
|
2
2
|
|
3
3
|
attr_accessor :headings, :rows
|
4
4
|
|
5
|
-
def initialize root
|
5
|
+
def initialize root, models
|
6
6
|
@root = root
|
7
|
+
@models = models
|
7
8
|
parse
|
8
9
|
end
|
9
10
|
|
10
11
|
def parse
|
11
|
-
system "rake routes > #{@root.path}/routes.txt"
|
12
|
-
rows = @root.find('routes.txt').lines.map{|line|
|
12
|
+
system "rake routes > #{@root.path}/routes.txt" if !File.exist? "#{@root.path}/routes.txt"
|
13
|
+
@rows = @root.find('routes.txt').lines.map{|line|
|
13
14
|
arr = line.split(' ')
|
14
15
|
arr.unshift(nil) if arr.size == 3
|
15
16
|
arr
|
16
|
-
}
|
17
|
-
.delete_if{|arr| arr.size >= 5 or arr.size <= 2 }
|
18
|
-
.map{|row|
|
17
|
+
}.delete_if{|arr| arr.size >= 5 or arr.size <= 2 }.map{|row|
|
19
18
|
controller, action = row[3].split('#')
|
19
|
+
controller_name = controller.split('/').last
|
20
|
+
if @models
|
21
|
+
@model_name = @models.models.include?(controller_name.singularize) ? controller_name.singularize : nil
|
22
|
+
end
|
20
23
|
type = row[1]
|
21
24
|
help_method = row[0]
|
22
25
|
uri = row[2]
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
|
27
|
-
@headings = ['控制器', 'action', '请求类型','URI','帮助方法']
|
28
|
-
@rows = rows
|
26
|
+
[@model_name,controller_name, action, type, uri, help_method]
|
27
|
+
}.sort{|a,b| a[1] <=> b[1]}
|
28
|
+
#File.delete("#{@root.path}/routes.txt") if File.exist? "#{@root.path}/routes.txt"
|
29
|
+
@headings = ['所属模型','控制器', 'action', '请求类型','URI','帮助方法']
|
29
30
|
end
|
30
31
|
end
|
data/lib/ld/version.rb
CHANGED