ld 0.1.9 → 0.1.10
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/lib/ld/file.rb +34 -34
- data/lib/ld/files.rb +18 -0
- data/lib/ld/project.rb +127 -12
- data/lib/ld/search_module.rb +3 -0
- data/lib/ld/sheet.rb +1 -1
- data/lib/ld/version.rb +1 -1
- data/lib/ld.rb +3 -3
- metadata +4 -5
- data/lib/ld/node.rb +0 -13
- data/lib/ld/nodes.rb +0 -33
- data/lib/ld/tree.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eef66e56fee081ece10f99a43b3b60d0bb8a6edc
|
4
|
+
data.tar.gz: e7d95cf09c210ad2a82f69cf75b42b3e1542147e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cbd1a4069f61e0448a3f6b180f707cb07ef59188505082b5397a25f76b6a1f75d8d0ce09084310221e3a5e949094d30d8fc8baf7210b2f15305cf076f9fddfc
|
7
|
+
data.tar.gz: c74cfc450556980ea3e1270854717de4644b7fae4d1e3a972788f60b65d0844a7adae29f2f7fb979fdb25c161ee4c8f4a3f3768abe61d29017ddd32a0c9c5064
|
data/lib/ld/file.rb
CHANGED
@@ -30,6 +30,40 @@ class Ld::File
|
|
30
30
|
arr
|
31
31
|
end
|
32
32
|
|
33
|
+
def search_files regexp
|
34
|
+
arr = []
|
35
|
+
iter_search_files regexp, arr
|
36
|
+
arr
|
37
|
+
end
|
38
|
+
|
39
|
+
def search_dirs
|
40
|
+
arr = []
|
41
|
+
iter_search_dir arr
|
42
|
+
arr
|
43
|
+
end
|
44
|
+
|
45
|
+
def iter_search_dir arr
|
46
|
+
children.each do |f|
|
47
|
+
if f.type == 1
|
48
|
+
arr << f
|
49
|
+
f.iter_search_dir arr
|
50
|
+
end
|
51
|
+
end
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def iter_search_files regexp, arr
|
56
|
+
children.each do |f|
|
57
|
+
if f.type == 1
|
58
|
+
f.iter_search_files regexp, arr
|
59
|
+
end
|
60
|
+
if f.name.match(regexp)
|
61
|
+
arr << f
|
62
|
+
end
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
33
67
|
def father
|
34
68
|
arr = @path.split('/')
|
35
69
|
arr.pop
|
@@ -54,40 +88,6 @@ class Ld::File
|
|
54
88
|
File.open(@path).readlines
|
55
89
|
end
|
56
90
|
|
57
|
-
def where regexp
|
58
|
-
arr = []
|
59
|
-
iter_search regexp, arr
|
60
|
-
arr
|
61
|
-
end
|
62
|
-
|
63
|
-
def search regexp
|
64
|
-
arr = []
|
65
|
-
iter_search regexp, arr
|
66
|
-
arr
|
67
|
-
end
|
68
|
-
|
69
|
-
def iter_search regexp, arr
|
70
|
-
children.each do |f|
|
71
|
-
if f.type == 1
|
72
|
-
f.iter_search regexp, arr
|
73
|
-
end
|
74
|
-
if f.name.match(regexp)
|
75
|
-
arr << f
|
76
|
-
end
|
77
|
-
end
|
78
|
-
self
|
79
|
-
end
|
80
|
-
|
81
|
-
def iter arr
|
82
|
-
children.each do |f|
|
83
|
-
if f.type == 1
|
84
|
-
f.iter arr
|
85
|
-
end
|
86
|
-
arr << f
|
87
|
-
end
|
88
|
-
self
|
89
|
-
end
|
90
|
-
|
91
91
|
def size
|
92
92
|
File.size path
|
93
93
|
end
|
data/lib/ld/files.rb
ADDED
data/lib/ld/project.rb
CHANGED
@@ -1,15 +1,130 @@
|
|
1
1
|
class Ld::Project
|
2
2
|
|
3
|
-
|
3
|
+
attr_accessor :app, :name, :models, :views_dir, :views, :controllers, :routes
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
def initialize
|
6
|
+
@@root = Ld::File.new Rails.root.to_s
|
7
|
+
system "rake routes > #{@@root.config.path}/routes.txt"
|
8
|
+
Ld::Excel.create "#{@@root.config.path}/project.xls" do |excel|
|
9
|
+
excel.write_sheet 'routes' do |sheet|
|
10
|
+
sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
|
11
|
+
sheet.set_headings ['控制器', 'action', '请求类型','URI','帮助方法']
|
12
|
+
sheet.set_point 'a1'
|
13
|
+
sheet.set_rows @@root.config.find('routes.txt').lines
|
14
|
+
.map{|line|
|
15
|
+
arr = line.split(' ')
|
16
|
+
arr.unshift(nil) if arr.size == 3
|
17
|
+
arr
|
18
|
+
}
|
19
|
+
.delete_if{|arr| arr.size == 5 }
|
20
|
+
.map{|row|
|
21
|
+
controller, action = row[3].split('#')
|
22
|
+
type = row[1]
|
23
|
+
help_method = row[0]
|
24
|
+
uri = row[2]
|
25
|
+
[controller, action, type, uri, help_method]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
excel.write_sheet 'models' do |sheet|
|
30
|
+
sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
|
31
|
+
sheet.set_point 'a1'
|
32
|
+
|
33
|
+
@models = @@root.app.models.search_files(/.rb$/)
|
34
|
+
@controllers = @@root.app.controllers.search_files(/_controller.rb$/)
|
35
|
+
@views = @@root.app.views.search_dirs
|
36
|
+
|
37
|
+
sheet.set_rows @models.map { |model_file|
|
38
|
+
model_name = model_file.name.split('.')[0]
|
39
|
+
model_lines = model_file.lines
|
40
|
+
actions_full_name = model_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
|
41
|
+
actions = actions_full_name.map{|action| action.split(' ')[0]}
|
42
|
+
model_instance = eval("#{model_name.camelize}.new")
|
43
|
+
fields = model_instance.attributes.keys
|
44
|
+
|
45
|
+
|
46
|
+
controller = find_controller model_name.pluralize
|
47
|
+
if controller
|
48
|
+
controller_lines = controller.lines
|
49
|
+
controller_methods = controller_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
|
50
|
+
end
|
51
|
+
|
52
|
+
view = find_view model_name.pluralize
|
53
|
+
if view
|
54
|
+
views = view.search_files(/.html/)
|
55
|
+
end
|
56
|
+
|
57
|
+
[
|
58
|
+
model_name, # 模型
|
59
|
+
model_name.camelize, # 类
|
60
|
+
model_lines.size, # 模型lines
|
61
|
+
model_file.path, # 模型文件
|
62
|
+
(controller.nil? ? '' : controller.path), # 控制器文件
|
63
|
+
(controller.nil? ? 0 : controller_lines.size),# 控制器lines
|
64
|
+
actions.size, # 模型方法size
|
65
|
+
actions.join(','), # 模型方法
|
66
|
+
fields.size, # 字段size
|
67
|
+
fields.join(','), # 字段
|
68
|
+
(views.nil? ? 0 : views.size), # 视图size
|
69
|
+
(views.nil? ? '' : views.map{|v| "#{v.name.split('.')[0]}-#{v.path}"}.join(',')), # 视图
|
70
|
+
(controller_methods.nil? ? 0 : controller_methods.size), # action-size
|
71
|
+
(controller_methods.nil? ? '' : controller_methods.join(',')) # actions
|
72
|
+
]
|
73
|
+
}.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序
|
74
|
+
|
75
|
+
sheet.set_row []
|
76
|
+
sheet.set_row []
|
77
|
+
sheet.set_headings ['模型','类',
|
78
|
+
'模型lines','模型文件',
|
79
|
+
'控制器文件','控制器lines',
|
80
|
+
'模型方法size','模型方法',
|
81
|
+
'字段size','字段',
|
82
|
+
'视图size', '视图',
|
83
|
+
'action-size','actions']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def find_controller model_name
|
89
|
+
@controllers.each do |c|
|
90
|
+
if c.name.split('_controller.rb')[0] == model_name
|
91
|
+
return c
|
92
|
+
end
|
93
|
+
end
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
def find_view model_name
|
97
|
+
@views.each do |v|
|
98
|
+
if v.name == model_name
|
99
|
+
return v
|
100
|
+
end
|
101
|
+
end
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
def camelize name
|
105
|
+
name.camelize
|
106
|
+
end
|
107
|
+
def name
|
108
|
+
@@root.name
|
109
|
+
end
|
110
|
+
def path
|
111
|
+
@@root.path
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def self.save_info
|
116
|
+
@@p ||= Ld::Project.new(Rails.root.to_s)
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.get_routes
|
121
|
+
@@p ||= Ld::Project.new(Rails.root.to_s)
|
122
|
+
file = Ld::File.new @@p.config.path + '/routes.txt'
|
123
|
+
system "rake routes > #{file.path}"
|
124
|
+
file.lines.map{|line| arr = line.split(' '); arr.size == 3 ? arr.unshift(nil) : arr}
|
125
|
+
t.headings = ['controller', 'action', 'type']
|
126
|
+
arrs.map{|arr| controller,action = arr[3].split('#'); [controller, action, arr[1]]}
|
127
|
+
.each{|arr| t.add_row arr}
|
13
128
|
end
|
14
129
|
|
15
130
|
def self.p model = :all
|
@@ -18,7 +133,7 @@ class Ld::Project
|
|
18
133
|
t = Terminal::Table.new
|
19
134
|
case model.to_s
|
20
135
|
when 'all'
|
21
|
-
t.title = "project:#{@@
|
136
|
+
t.title = "project:#{@@root.name}"
|
22
137
|
t.headings = ['models', 'views', 'controllers', 'routes']
|
23
138
|
t.add_row [@@p.models.size, @@p.views.size, @@p.controllers.size, @@p.routes.lines.size]
|
24
139
|
when 'models'
|
@@ -39,9 +154,9 @@ class Ld::Project
|
|
39
154
|
.sort{|a,b| b[1]-a[1]}
|
40
155
|
.each{|arr| t.add_row arr}
|
41
156
|
when 'routes'
|
42
|
-
file = Ld::File.new @@
|
157
|
+
file = Ld::File.new @@root.path + '/routes.txt'
|
43
158
|
if !file.exist?
|
44
|
-
system "rake routes > #{@@
|
159
|
+
system "rake routes > #{@@root.path + '/routes.txt'}"
|
45
160
|
end
|
46
161
|
arrs = file.lines.map{|l| lines = l.split(' '); lines.size == 3 ? lines.unshift(nil) : lines}
|
47
162
|
arrs.delete_at 0
|
data/lib/ld/sheet.rb
CHANGED
data/lib/ld/version.rb
CHANGED
data/lib/ld.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.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-
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: terminal-table
|
@@ -95,12 +95,11 @@ files:
|
|
95
95
|
- lib/ld/dir.rb
|
96
96
|
- lib/ld/excel.rb
|
97
97
|
- lib/ld/file.rb
|
98
|
-
- lib/ld/
|
99
|
-
- lib/ld/nodes.rb
|
98
|
+
- lib/ld/files.rb
|
100
99
|
- lib/ld/project.rb
|
100
|
+
- lib/ld/search_module.rb
|
101
101
|
- lib/ld/sheet.rb
|
102
102
|
- lib/ld/table.rb
|
103
|
-
- lib/ld/tree.rb
|
104
103
|
- lib/ld/version.rb
|
105
104
|
homepage: https://github.com/18810625123/ld
|
106
105
|
licenses:
|
data/lib/ld/node.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
class Ld::Node
|
2
|
-
attr_accessor :id, :depth, :name, :path ,:type, :suffix
|
3
|
-
|
4
|
-
def initialize id, depth, path
|
5
|
-
@id = id
|
6
|
-
@depth = depth
|
7
|
-
@path = path
|
8
|
-
@type = File.directory?(path) ? 1 : 0
|
9
|
-
@name = File.basename path
|
10
|
-
@suffix = @type == 1 ? nil : @name.split('.').last
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/lib/ld/nodes.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
class Ld::Nodes
|
2
|
-
attr_accessor :nodes
|
3
|
-
|
4
|
-
def initialize nodes = []
|
5
|
-
@nodes = nodes
|
6
|
-
end
|
7
|
-
|
8
|
-
def << node
|
9
|
-
@nodes << node
|
10
|
-
end
|
11
|
-
|
12
|
-
def where option
|
13
|
-
sql = ""
|
14
|
-
if option.instance_of?(String)
|
15
|
-
sql = option
|
16
|
-
elsif option.instance_of?(Hash)
|
17
|
-
sql = option.map{|k,v| "node.#{k} == #{v.instance_of?(String) ? "'#{v}'" : "#{v}"}"}.join(" and ")
|
18
|
-
end
|
19
|
-
@nodes.map{|node| if(eval(sql));node;end}.compact
|
20
|
-
end
|
21
|
-
|
22
|
-
def find id
|
23
|
-
@nodes.each{|node| return node if node.id == id}
|
24
|
-
end
|
25
|
-
|
26
|
-
def size
|
27
|
-
@nodes.size
|
28
|
-
end
|
29
|
-
|
30
|
-
def sort_by_depth
|
31
|
-
@nodes.sort{|a,b| a.depth - b.depth}
|
32
|
-
end
|
33
|
-
end
|
data/lib/ld/tree.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
class Ld::Tree
|
2
|
-
attr_accessor :root_path, :root_name, :nodes, :depth, :id
|
3
|
-
|
4
|
-
def initialize root_path
|
5
|
-
@root_path = root_path
|
6
|
-
@root_name = File.basename root_path
|
7
|
-
@nodes = Ld::Nodes.new
|
8
|
-
@numbers = 0
|
9
|
-
@depth = 0
|
10
|
-
@id = 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def read_tree path = @root_path
|
14
|
-
@depth+=1
|
15
|
-
Dir.foreach(path)do |p|
|
16
|
-
if !p.match(/^\./)
|
17
|
-
node = Ld::Node.new(@id+=1, @depth, "#{path}/#{p}")
|
18
|
-
@nodes << node
|
19
|
-
if node.type == 1
|
20
|
-
read_tree node.path
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def print_tree
|
27
|
-
puts "#{@root_name}:"
|
28
|
-
@nodes.sort_by_depth.each do |node|
|
29
|
-
if node.type == 1
|
30
|
-
print_tree
|
31
|
-
else
|
32
|
-
puts "\t"*node.id + "#{node.type}:#{node.name}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|