ld 0.2.6 → 0.2.7

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: d537a523fd57cca3f98c2662fc9ac9a208b7522b
4
- data.tar.gz: 492bba9c5d819c7e58a063f0bc791679c2a6e873
3
+ metadata.gz: c5e6b6b049c3500199fc6a575bb77171b91fcf29
4
+ data.tar.gz: 8af7fdc85064507fe94bd42cba74772af06edb05
5
5
  SHA512:
6
- metadata.gz: 3044f77a5e29d12d8b4aee5e3af93ac79bfa74f8d906749181116e1dfac1dfed264522b55ef055990297bc0a8b539ca3e3bff191324a53ffa749fffce3662df2
7
- data.tar.gz: 6c326e0433bde9e60f55c2259871549eb39c8f9de1e1b4c22d246f0900462ffe79d4281b0c02a7edb89aa83ce504f08c52c690f2006663ee4c2f8ad59c209f3e
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
- # Print model, Need to change the User model to exist, to run again
68
- Ld::Table.p User.all, 'id , created_at'
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 '/Users/liudong/Desktop/excel_test.xls' do |excel|
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
- (1..10).to_a.each do |i|
77
- sheet.add_row i.times.map{|j| j}
78
- end
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
- # Read xls
83
- Ld::Excel.open('/Users/liudong/Desktop/excel_test.xls').read('sheet1?a1:e10')
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
- # Project Structure details to /project.xls 查看项目详情,会生成xls文件,在: /project.xls
89
- Ld::Project::Structure.new(Ld::File.new(Rails.root.to_s)).generate
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
 
@@ -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
- [name,name.pluralize,name.camelize,data_count,lines.size,file.path,methods.size,methods.join(','),fields.join(','),fields.size]
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
@@ -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
@@ -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
- [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
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
@@ -1,3 +1,3 @@
1
1
  module Ld
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Dong