Class: Ld::Project
- Inherits:
-
Object
- Object
- Ld::Project
- Defined in:
- lib/ld/project/project.rb
Instance Attribute Summary collapse
-
#controllers ⇒ Object
Returns the value of attribute controllers.
-
#models ⇒ Object
Returns the value of attribute models.
-
#root ⇒ Object
Returns the value of attribute root.
-
#routes ⇒ Object
Returns the value of attribute routes.
-
#table_hash ⇒ Object
Returns the value of attribute table_hash.
-
#tables ⇒ Object
Returns the value of attribute tables.
-
#views ⇒ Object
Returns the value of attribute views.
Instance Method Summary collapse
- #add_bug ⇒ Object
- #delete_rows_index ⇒ Object
-
#initialize(table_hash = {}, project_root_path = Rails.root.to_s) ⇒ Project
constructor
A new instance of Project.
- #parse_project ⇒ Object
- #print(model_name, type = :relations) ⇒ Object
- #to_xls(path = {:file_path => "#{@root.path}/project.xls"}) ⇒ Object
Constructor Details
#initialize(table_hash = {}, project_root_path = Rails.root.to_s) ⇒ Project
Returns a new instance of Project.
5 6 7 8 9 10 11 12 |
# File 'lib/ld/project/project.rb', line 5 def initialize table_hash = {}, project_root_path = Rails.root.to_s @root = Ld::File.new project_root_path @table_hash = table_hash @schema = @root.db.find('schema.rb') raise "schema.rb文件不存在\n请运行命令(rake db:schema:dump)或手动添加此文件" if @schema.nil? raise "schema.rb文件是空的\n请运行命令(rake db:schema:dump)或手动添加此文件" if @schema.lines.size == 0 parse_project end |
Instance Attribute Details
#controllers ⇒ Object
Returns the value of attribute controllers.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def controllers @controllers end |
#models ⇒ Object
Returns the value of attribute models.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def models @models end |
#root ⇒ Object
Returns the value of attribute root.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def root @root end |
#routes ⇒ Object
Returns the value of attribute routes.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def routes @routes end |
#table_hash ⇒ Object
Returns the value of attribute table_hash.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def table_hash @table_hash end |
#tables ⇒ Object
Returns the value of attribute tables.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def tables @tables end |
#views ⇒ Object
Returns the value of attribute views.
3 4 5 |
# File 'lib/ld/project/project.rb', line 3 def views @views end |
Instance Method Details
#add_bug ⇒ Object
128 129 130 |
# File 'lib/ld/project/project.rb', line 128 def add_bug end |
#delete_rows_index ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/ld/project/project.rb', line 93 def delete_rows_index @routes.rows.delete_at 0 @tables.rows.delete_at 0 @models.rows.delete_at 0 @views.rows.delete_at 0 @controllers.rows.delete_at 0 end |
#parse_project ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/ld/project/project.rb', line 14 def parse_project @tables = Ld::Tables.new @root, nil @models = Ld::Models.new @root, @tables, @table_hash @routes = Ld::Routes.new @root, @models @tables = Ld::Tables.new @root, @models @views = Ld::Views.new @root, @models @controllers = Ld::Controllers.new @root, @models end |
#print(model_name, type = :relations) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ld/project/project.rb', line 23 def print model_name, type = :relations model_name = model_name.to_s if !@models.models.include? model_name puts "不存在 #{model_name}" return false end title_str = "#{model_name.camelize}(#{@table_hash[model_name]})" type = type.to_sym case type when :fields fs = '字段,字段类型,描述,空约束,默认值,精度位数,limit'.split(',') indexs = fs.map{|f| @tables.headings.index(f)}.compact rows = [] @tables.rows.select{|a| a[0]==model_name} .each{|arr| rows << indexs.map{|i| arr[i]} } puts Terminal::Table.new( :title => "#{title_str}:字段解释", :headings => fs, :rows => rows ) when :relations fs = 'has_many,belongs_to,has_one'.split(',') indexs = fs.map{|f| @models.headings.index(f)}.compact rows = [] @models.rows.select{|a| a[0]==model_name}. each{|arr| rows << indexs.map{|i| arr[i]} } puts Terminal::Table.new( :title => "#{title_str}:关联关系", :headings => fs, :rows => rows ) when :routes fs = '控制器,action,请求类型,URI,帮助方法'.split(',') indexs = fs.map{|f| @routes.headings.index(f)}.compact rows = [] @routes.rows.select{|a| a[0]==model_name}. each{|arr| rows << indexs.map{|i| arr[i]} } puts Terminal::Table.new( :title => "#{title_str}:路由", :headings => fs, :rows => rows ) when :views fs = '文件夹名,行数,文件名,path'.split(',') indexs = fs.map{|f| @views.headings.index(f)}.compact rows = [] @views.rows.select{|a| a[0]==model_name}. each{|arr| rows << indexs.map{|i| arr[i]} } puts Terminal::Table.new( :title => "#{title_str}:视图", :headings => fs, :rows => rows ) when :controllers fs = 'action个数,文件行数,所有action'.split(',') indexs = fs.map{|f| @controllers.headings.index(f)}.compact rows = [] @controllers.rows.select{|a| a[0]==model_name}. each{|arr| rows << indexs.map{|i| arr[i]} } puts Terminal::Table.new( :title => "#{title_str}:控制器", :headings => fs, :rows => rows ) end true end |
#to_xls(path = {:file_path => "#{@root.path}/project.xls"}) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/ld/project/project.rb', line 101 def to_xls path = {:file_path => "#{@root.path}/project.xls"} Ld::Excel.create path do |excel| excel.write_sheet 'routes' do |sheet| sheet.set_format({color: :red, font_size: 14, font: '微软雅黑'}) sheet.set_headings @routes.headings sheet.set_rows @routes.rows end excel.write_sheet 'tables' do |sheet| sheet.set_headings @tables.headings sheet.set_rows @tables.rows end excel.write_sheet 'models' do |sheet| sheet.set_headings @models.headings sheet.set_rows @models.rows end excel.write_sheet 'views' do |sheet| sheet.set_headings @views.headings sheet.set_rows @views.rows end excel.write_sheet 'controllers' do |sheet| sheet.set_headings @controllers.headings sheet.set_rows @controllers.rows end end #delete_rows_index end |