lib/ld/project.rb in ld-0.1.10 vs lib/ld/project.rb in ld-0.1.11

- old
+ new

@@ -14,30 +14,59 @@ .map{|line| arr = line.split(' ') arr.unshift(nil) if arr.size == 3 arr } - .delete_if{|arr| arr.size == 5 } + .delete_if{|arr| arr.size >= 5 or arr.size <= 2 } .map{|row| controller, action = row[3].split('#') type = row[1] help_method = row[0] uri = row[2] [controller, action, type, uri, help_method] } end + excel.write_sheet 'tables' do |sheet| + sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'}) + sheet.set_headings ['tables', 'commit'] + sheet.set_point 'a1' + lines = @@root.db.find('schema.rb').lines + @tables = {} + read_flag = false + table = "" + lines.each do |l| + if l.lstrip.rstrip.split('end').size == 0 + read_flag = false + end + if l.match(/create_table /) and l.match(/ do /) + read_flag = true + table = l.split('"')[1] + @tables[table] = [] + end + if read_flag + @tables[table] << l + end + end + @tables.each do |k, v| + v.delete_at(0) + sheet.set_row [k, v.join(':')] + end + end excel.write_sheet 'models' do |sheet| sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'}) sheet.set_point 'a1' @models = @@root.app.models.search_files(/.rb$/) @controllers = @@root.app.controllers.search_files(/_controller.rb$/) @views = @@root.app.views.search_dirs - sheet.set_rows @models.map { |model_file| + rows = [] + @models.each do |model_file| model_name = model_file.name.split('.')[0] + next if @tables[model_name.pluralize].nil? + model_lines = model_file.lines actions_full_name = model_lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact actions = actions_full_name.map{|action| action.split(' ')[0]} model_instance = eval("#{model_name.camelize}.new") fields = model_instance.attributes.keys @@ -52,11 +81,11 @@ view = find_view model_name.pluralize if view views = view.search_files(/.html/) end - [ + rows << [ model_name, # 模型 model_name.camelize, # 类 model_lines.size, # 模型lines model_file.path, # 模型文件 (controller.nil? ? '' : controller.path), # 控制器文件 @@ -68,10 +97,12 @@ (views.nil? ? 0 : views.size), # 视图size (views.nil? ? '' : views.map{|v| "#{v.name.split('.')[0]}-#{v.path}"}.join(',')), # 视图 (controller_methods.nil? ? 0 : controller_methods.size), # action-size (controller_methods.nil? ? '' : controller_methods.join(',')) # actions ] - }.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序 + end + rows = rows.compact.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序 + sheet.set_rows rows sheet.set_row [] sheet.set_row [] sheet.set_headings ['模型','类', '模型lines','模型文件', \ No newline at end of file