Sha256: 2c1d2f4fbbf2af7f5c9b2ffc1d079e074cad4ddfadd44decd4dcd51839563f10

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

class Ld::Models
  attr_accessor :headings, :rows, :models

  def initialize root, tables
    @root = root
    @tables = tables
    parse
  end

  def parse
    rows =  []
    model_files = @root.app.models.search_files(/.rb$/).map{|m|
      m if @tables.tables.include?(m.name.split('.')[0].pluralize)
    }.compact
    @rows = model_files.map{ |file|
      name    = file.name.split('.')[0]
      lines   = file.lines
      methods_full = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact
      methods = methods_full.map{|method_full| method_full.split(' ')[0]}
      instance = name.camelize.constantize.new
      data_count = name.camelize.constantize.count
      fields = instance.attributes.keys
      [name,name.pluralize,name.camelize,data_count,lines.size,file.path,methods.size,methods.join(','),fields.join(','),fields.size]
    }.compact.sort{|a,b| b[2] <=> a[2]} # 按 模型文件行数 排序
    @models = @rows.map{|arr| arr[0]}.uniq
    @headings = ['模型名','表名','类','数据数量','行数','path', '方法数','所有方法', '所有字段','字段数量']
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ld-0.2.6 lib/ld/project/models.rb