ld 0.2.3 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4af0a7c07134cdf6d742c1b88cc238550a2a2d46
4
- data.tar.gz: 7eb292821386f94588ed38e9656f33ef7f8ab123
3
+ metadata.gz: d537a523fd57cca3f98c2662fc9ac9a208b7522b
4
+ data.tar.gz: 492bba9c5d819c7e58a063f0bc791679c2a6e873
5
5
  SHA512:
6
- metadata.gz: 71639346308ef0deeaac90d99b8a12b9dc83f959a6beb948bae9d23dfa624d0161bfbf77a55bb53b667ef3c40cc18c407e579ed402dc10a818f540ca764af5eb
7
- data.tar.gz: eb4dc802ce64338a46d7a7819494e1415f2380af4fc05bfe4bc036371e819e5bc8d7244d0d4f94b71d2fe0427547bae806a095686ebb9ce02971f69dc27c5fc1
6
+ metadata.gz: 3044f77a5e29d12d8b4aee5e3af93ac79bfa74f8d906749181116e1dfac1dfed264522b55ef055990297bc0a8b539ca3e3bff191324a53ffa749fffce3662df2
7
+ data.tar.gz: 6c326e0433bde9e60f55c2259871549eb39c8f9de1e1b4c22d246f0900462ffe79d4281b0c02a7edb89aa83ce504f08c52c690f2006663ee4c2f8ad59c209f3e
data/README.md CHANGED
@@ -85,8 +85,8 @@ Ld::Excel.open('/Users/liudong/Desktop/excel_test.xls').read('sheet1?a1:e10')
85
85
  # Read Dir
86
86
  Ld::File.open_dir('dir_path').children.each{|f| puts f.path}
87
87
 
88
- # Project details to xls 查看项目详情,会生成xls文件,在: config/project.xls
89
- Ld::Project.new
88
+ # Project Structure details to /project.xls 查看项目详情,会生成xls文件,在: /project.xls
89
+ Ld::Project::Structure.new(Ld::File.new(Rails.root.to_s)).generate
90
90
 
91
91
  ```
92
92
 
@@ -0,0 +1,40 @@
1
+ class Ld::Controllers
2
+
3
+ attr_accessor :headings, :rows
4
+
5
+ def initialize root, models
6
+ @root = root
7
+ @models = models
8
+ parse
9
+ end
10
+
11
+ def parse
12
+ @rows = @root.app.controllers.search_files(/_controller.rb$/).map { |c|
13
+ model_name = c.name.split('_controller')[0].singularize
14
+ model_name = @models.models.include?(model_name) ? model_name : nil
15
+ lines = c.lines
16
+ actions = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
17
+ [model_name, c.name,actions.size, lines.size, c.path,actions.join(',')]
18
+ }.sort{|a,b| b[2] <=> a[2]}
19
+ @headings = ['所属模型名称', '控制器名','action个数', '文件行数','path', '所有action']
20
+ end
21
+
22
+ def parse_by_model_name model_name
23
+ controller = find_controller model_name.pluralize
24
+ if controller
25
+ controller_lines = controller.lines
26
+ controller_methods = controller_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
27
+ end
28
+ controller
29
+ end
30
+
31
+ def find_controller model_name
32
+ @controllers.each do |c|
33
+ if c.name.split('_controller.rb')[0] == model_name
34
+ return c
35
+ end
36
+ end
37
+ nil
38
+ end
39
+
40
+ end
@@ -0,0 +1,30 @@
1
+ class Ld::Models
2
+ attr_accessor :headings, :rows, :models
3
+
4
+ def initialize root, tables
5
+ @root = root
6
+ @tables = tables
7
+ parse
8
+ end
9
+
10
+ def parse
11
+ rows = []
12
+ model_files = @root.app.models.search_files(/.rb$/).map{|m|
13
+ m if @tables.tables.include?(m.name.split('.')[0].pluralize)
14
+ }.compact
15
+ @rows = model_files.map{ |file|
16
+ name = file.name.split('.')[0]
17
+ lines = file.lines
18
+ methods_full = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
19
+ methods = methods_full.map{|method_full| method_full.split(' ')[0]}
20
+ instance = name.camelize.constantize.new
21
+ data_count = name.camelize.constantize.count
22
+ fields = instance.attributes.keys
23
+ [name,name.pluralize,name.camelize,data_count,lines.size,file.path,methods.size,methods.join(','),fields.join(','),fields.size]
24
+ }.compact.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序
25
+ @models = @rows.map{|arr| arr[0]}.uniq
26
+ @headings = ['模型名','表名','类','数据数量','行数','path', '方法数','所有方法', '所有字段','字段数量']
27
+ end
28
+
29
+
30
+ end
@@ -0,0 +1,51 @@
1
+ class Ld::Project
2
+
3
+ attr_accessor :root, :tables, :models, :controllers, :views, :routes
4
+
5
+ def initialize path = Rails.root.to_s
6
+ @root = Ld::File.new path
7
+ end
8
+
9
+ def parse_project
10
+ @routes = Ld::Routes.new @root
11
+ @tables = Ld::Tables.new @root, nil
12
+ @models = Ld::Models.new @root, @tables
13
+ @tables = Ld::Tables.new @root, @models
14
+ @views = Ld::Views.new @root, @models
15
+ @controllers = Ld::Controllers.new @root, @models
16
+ end
17
+
18
+ def to_xls path = "#{@root.path}/project.xls"
19
+ parse_project
20
+ Ld::Excel.create path do |excel|
21
+ # sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
22
+ excel.write_sheet 'routes' do |sheet|
23
+ sheet.set_headings @routes.headings
24
+ sheet.set_rows @routes.rows
25
+ end
26
+ excel.write_sheet 'tables' do |sheet|
27
+ sheet.set_headings @tables.headings
28
+ sheet.set_rows @tables.rows
29
+ end
30
+ excel.write_sheet 'models' do |sheet|
31
+ sheet.set_headings @models.headings
32
+ sheet.set_rows @models.rows
33
+ end
34
+ excel.write_sheet 'views' do |sheet|
35
+ sheet.set_headings @views.headings
36
+ sheet.set_rows @views.rows
37
+ end
38
+ excel.write_sheet 'controllers' do |sheet|
39
+ sheet.set_headings @controllers.headings
40
+ sheet.set_rows @controllers.rows
41
+ end
42
+ end
43
+ end
44
+
45
+
46
+ def camelize name
47
+ name.camelize
48
+ end
49
+
50
+
51
+ end
@@ -0,0 +1,30 @@
1
+ class Ld::Routes
2
+
3
+ attr_accessor :headings, :rows
4
+
5
+ def initialize root
6
+ @root = root
7
+ parse
8
+ end
9
+
10
+ def parse
11
+ system "rake routes > #{@root.path}/routes.txt"
12
+ rows = @root.find('routes.txt').lines.map{|line|
13
+ arr = line.split(' ')
14
+ arr.unshift(nil) if arr.size == 3
15
+ arr
16
+ }
17
+ .delete_if{|arr| arr.size >= 5 or arr.size <= 2 }
18
+ .map{|row|
19
+ controller, action = row[3].split('#')
20
+ type = row[1]
21
+ help_method = row[0]
22
+ uri = row[2]
23
+ #
24
+ [controller, action, type, uri, help_method]
25
+ }
26
+ File.delete("#{@root.path}/routes.txt") if File.exist? "#{@root.path}/routes.txt"
27
+ @headings = ['控制器', 'action', '请求类型','URI','帮助方法']
28
+ @rows = rows
29
+ end
30
+ end
@@ -0,0 +1,81 @@
1
+ class Ld::Tables
2
+
3
+ attr_accessor :headings, :rows, :tables
4
+
5
+ def initialize root, models
6
+ @root = root
7
+ @models = models
8
+ parse
9
+ end
10
+
11
+ def parse
12
+ tables = {}
13
+ read_flag = false
14
+ table = ""
15
+ @root.db.find('schema.rb').lines.each do |l|
16
+ if l.split(' ')[0] == 'end'
17
+ read_flag = false
18
+ end
19
+ if l.split(' ')[0] == 'create_table'
20
+ read_flag = true
21
+ table = l.split('"')[1]
22
+ tables[table] = []
23
+ end
24
+ if read_flag
25
+ tables[table] << l
26
+ end
27
+ end
28
+ rows = []
29
+ tables.each do |table_name, lines|
30
+ model_class = parse_class table_name
31
+ lines.delete_at(0)
32
+ lines.each do |line|
33
+ hash = parse_line line
34
+ if hash[:type] != 'index'
35
+ if @models
36
+ @model_name = @models.models.include?(table_name.singularize) ? table_name.singularize : nil
37
+ end
38
+ rows << [@model_name,table_name,hash[:field],hash[:type],hash[:comment],hash[:null],hash[:default],hash[:precision],hash[:limit]]
39
+ end
40
+ end
41
+ end
42
+ @headings = ['所属模型','表名','字段','字段类型','描述','空约束','默认值','精度位数','limit']
43
+ @rows = rows.sort{|a,b| b[1] <=> a[1]}
44
+ @tables = tables.keys
45
+ end
46
+
47
+ def parse_line line
48
+ arr = line.split(' ')
49
+ hash = {}
50
+ if arr[0].match(/^t./)
51
+ hash[:type] = arr[0].split('.')[1]
52
+ i = nil
53
+ if hash[:type] == 'index'
54
+ hash[:name] = arr[i + 1] if i = arr.index('name:')
55
+ hash[:unique] = arr[i + 1] if i = arr.index('unique:')
56
+ hash[:using] = arr[i + 1] if i = arr.index('using:')
57
+ else
58
+ hash[:field] = line.split('"')[1]
59
+ hash[:null] = arr[i + 1] if i = arr.index('name:')
60
+ hash[:limit] = arr[i + 1] if i = arr.index('limit:')
61
+ hash[:comment] = arr[i + 1].split('"')[1] if i = arr.index('comment:')
62
+ hash[:default] = arr[i + 1] if i = arr.index('default:')
63
+ hash[:precision] = arr[i + 1] if i = arr.index('precision:')
64
+ hash[:precision] = arr[i + 1] if i = arr.index('precision:')
65
+ end
66
+ return hash
67
+ else
68
+
69
+ end
70
+ return false
71
+ end
72
+
73
+ def parse_class table_name
74
+ model_class = table_name.singularize.camelize.constantize
75
+ return model_class
76
+ rescue
77
+ return nil
78
+ end
79
+
80
+
81
+ end
@@ -0,0 +1,28 @@
1
+ class Ld::Views
2
+ attr_accessor :headings, :rows
3
+
4
+ def initialize root, models
5
+ @root = root
6
+ @models = models
7
+ parse
8
+ end
9
+
10
+ def parse
11
+ @rows = @root.app.views.search_files(/.html/).map{|v|
12
+ dir_name = v.father.name
13
+ model_name = @models.models.include?(dir_name.singularize) ? dir_name.singularize : nil
14
+ [model_name,v.lines.size,dir_name,v.name,v.path]
15
+ }.sort{|a,b| b[1] <=> a[1]}
16
+ @headings = ['所属模型名','行数','文件夹名','文件名','path']
17
+ end
18
+
19
+ def find model_name
20
+ @view_dirs.each do |view_dir|
21
+ if view_dir.name == model_name.pluralize
22
+ return Ld::View.new view_dir
23
+ end
24
+ end
25
+ nil
26
+ end
27
+
28
+ end
data/lib/ld/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ld
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.6"
3
3
  end
data/lib/ld.rb CHANGED
@@ -1,17 +1,17 @@
1
1
  require "ld/version"
2
2
 
3
3
  module Ld
4
- module Project
5
- module Parse
6
- end
7
- end
8
4
  end
9
5
 
10
6
  require "ld/file/file"
11
7
  require "ld/file/files"
12
8
 
13
- require "ld/project/parse"
14
- require "ld/project/structure"
9
+ require "ld/project/project"
10
+ require "ld/project/routes"
11
+ require "ld/project/tables"
12
+ require "ld/project/models"
13
+ require "ld/project/controllers"
14
+ require "ld/project/views"
15
15
 
16
16
  require "ld/excel/excel"
17
17
  require "ld/excel/sheet"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Dong
@@ -98,8 +98,12 @@ files:
98
98
  - lib/ld/file/file.rb
99
99
  - lib/ld/file/files.rb
100
100
  - lib/ld/print/print.rb
101
- - lib/ld/project/parse.rb
102
- - lib/ld/project/structure.rb
101
+ - lib/ld/project/controllers.rb
102
+ - lib/ld/project/models.rb
103
+ - lib/ld/project/project.rb
104
+ - lib/ld/project/routes.rb
105
+ - lib/ld/project/tables.rb
106
+ - lib/ld/project/views.rb
103
107
  - lib/ld/version.rb
104
108
  homepage: https://github.com/18810625123/ld
105
109
  licenses:
@@ -1,110 +0,0 @@
1
- module Ld::Project::Parse
2
-
3
- def parse_routes root
4
- system "rake routes > #{root.path}/routes.txt"
5
- rows = root.find('routes.txt').lines.map{|line|
6
- arr = line.split(' ')
7
- arr.unshift(nil) if arr.size == 3
8
- arr
9
- }
10
- .delete_if{|arr| arr.size >= 5 or arr.size <= 2 }
11
- .map{|row|
12
- controller, action = row[3].split('#')
13
- type = row[1]
14
- help_method = row[0]
15
- uri = row[2]
16
- #
17
- [controller, action, type, uri, help_method]
18
- }
19
- File.delete("#{root.path}/routes.txt") if File.exist? "#{root.path}/routes.txt"
20
- {
21
- :headings => ['控制器', 'action', '请求类型','URI','帮助方法'],
22
- :rows => rows
23
- }
24
- end
25
-
26
- def parse_schema root
27
- lines = root.db.find('schema.rb').lines
28
- tables = {}
29
- read_flag = false
30
- table = ""
31
- lines.each do |l|
32
- if l.lstrip.rstrip.split('end').size == 0
33
- read_flag = false
34
- end
35
- if l.match(/create_table /) and l.match(/ do /)
36
- read_flag = true
37
- table = l.split('"')[1]
38
- tables[table] = []
39
- end
40
- if read_flag
41
- tables[table] << l
42
- end
43
- end
44
- rows = tables.map{|k, v|
45
- v.delete_at(0)
46
- [k, v.join(':')]
47
- }
48
- {
49
- :headings => ['tables', 'comment'],
50
- :rows => rows
51
- }
52
- end
53
-
54
- def parse_models root
55
- rows = []
56
- @models = root.app.models.search_files(/.rb$/)
57
- @controllers = root.app.controllers.search_files(/_controller.rb$/)
58
- @views = root.app.views.search_dirs
59
- @tables = parse_schema root
60
- @models.each do |model_file|
61
- model_name = model_file.name.split('.')[0]
62
- next if !@tables[model_name.pluralize]
63
- model_lines = model_file.lines
64
- actions_full_name = model_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
65
- actions = actions_full_name.map{|action| action.split(' ')[0]}
66
- model_instance = eval("#{model_name.camelize}.new")
67
- fields = model_instance.attributes.keys
68
-
69
- controller = find_controller model_name.pluralize
70
- if controller
71
- controller_lines = controller.lines
72
- controller_methods = controller_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
73
- end
74
-
75
- view = find_view model_name.pluralize
76
- if view
77
- views = view.search_files(/.html/)
78
- end
79
-
80
- rows << [
81
- model_name, # 模型
82
- model_name.camelize, # 类
83
- model_lines.size, # 模型lines
84
- model_file.path, # 模型文件
85
- (controller.nil? ? '' : controller.path), # 控制器文件
86
- (controller.nil? ? 0 : controller_lines.size),# 控制器lines
87
- actions.size, # 模型方法size
88
- actions.join(','), # 模型方法
89
- fields.size, # 字段size
90
- fields.join(','), # 字段
91
- (views.nil? ? 0 : views.size), # 视图size
92
- (views.nil? ? '' : views.map{|v| "#{v.name.split('.')[0]}-#{v.path}"}.join(',')), # 视图
93
- (controller_methods.nil? ? 0 : controller_methods.size), # action-size
94
- (controller_methods.nil? ? '' : controller_methods.join(',')) # actions
95
- ]
96
- end
97
- rows = rows.compact.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序
98
- {
99
- :headings => ['模型','类',
100
- '模型lines','模型文件',
101
- '控制器文件','控制器lines',
102
- '模型方法size','模型方法',
103
- '字段size','字段',
104
- '视图size', '视图',
105
- 'action-size','actions'],
106
- :rows => rows
107
- }
108
- end
109
-
110
- end
@@ -1,57 +0,0 @@
1
- class Ld::Project::Structure
2
- include Ld::Project::Parse
3
- attr_accessor :root, :name, :path
4
-
5
- def initialize path = Rails.root.to_s
6
- @root = Ld::File.new path
7
- @name = @root.name
8
- @path = @root.path
9
- end
10
-
11
-
12
-
13
- def generate path = "#{@root.path}/project.xls"
14
- Ld::Excel.create path do |excel|
15
- # sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
16
- excel.write_sheet 'routes' do |sheet|
17
- @routes = parse_routes @root
18
- sheet.set_headings @routes[:headings]
19
- sheet.set_rows @routes[:rows]
20
- end
21
- excel.write_sheet 'tables' do |sheet|
22
- @tables = parse_schema @root
23
- sheet.set_headings @tables[:headings]
24
- sheet.set_rows @tables[:rows]
25
- end
26
- excel.write_sheet 'models' do |sheet|
27
- @models = parse_models @root
28
- sheet.set_headings @models[:headings]
29
- sheet.set_rows @models[:rows]
30
- end
31
- end
32
- end
33
-
34
- def find_controller model_name
35
- @controllers.each do |c|
36
- if c.name.split('_controller.rb')[0] == model_name
37
- return c
38
- end
39
- end
40
- nil
41
- end
42
-
43
- def find_view model_name
44
- @views.each do |v|
45
- if v.name == model_name
46
- return v
47
- end
48
- end
49
- nil
50
- end
51
-
52
- def camelize name
53
- name.camelize
54
- end
55
-
56
-
57
- end