class Ld::Project

Attributes

controllers[RW]
models[RW]
root[RW]
routes[RW]
table_hash[RW]
tables[RW]
views[RW]

Public Class Methods

new(table_hash = {}) click to toggle source

作用 解析一个项目的代码获得结构化的数据

# File lib/ld/project/project.rb, line 6
def initialize table_hash = {}, project_root_path = Rails.root.to_s
  @root = Ld::File.new project_root_path
  @table_hash = table_hash
  @schema = @root.find('db/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

Public Instance Methods

add_bug() click to toggle source
# File lib/ld/project/project.rb, line 131
def add_bug

end
delete_rows_index() click to toggle source
# File lib/ld/project/project.rb, line 95
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() click to toggle source
# File lib/ld/project/project.rb, line 15
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) click to toggle source

作用 查看模型的相关信息(参数有:relations,fields,tables,routes,views,controllers)

to_xls(path = {:file_path => " click to toggle source

作用 将这个项目的代码分析结果保存到excel文件(默认在项目根目录下的project.xls)

# File lib/ld/project/project.rb, line 104
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