Class: Ld::Project::Structure

Inherits:
Object
  • Object
show all
Includes:
Parse
Defined in:
lib/ld/project/structure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parse

#parse_models, #parse_routes, #parse_schema

Constructor Details

#initialize(path = Rails.root.to_s) ⇒ Structure

Returns a new instance of Structure.



5
6
7
8
9
# File 'lib/ld/project/structure.rb', line 5

def initialize path = Rails.root.to_s
  @root = Ld::File.new path
  @name = @root.name
  @path = @root.path
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/ld/project/structure.rb', line 3

def name
  @name
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/ld/project/structure.rb', line 3

def path
  @path
end

#rootObject

Returns the value of attribute root.



3
4
5
# File 'lib/ld/project/structure.rb', line 3

def root
  @root
end

Instance Method Details

#camelize(name) ⇒ Object



52
53
54
# File 'lib/ld/project/structure.rb', line 52

def camelize name
  name.camelize
end

#find_controller(model_name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/ld/project/structure.rb', line 34

def find_controller model_name
  @controllers.each do |c|
    if c.name.split('_controller.rb')[0] == model_name
      return c
    end
  end
  nil
end

#find_view(model_name) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ld/project/structure.rb', line 43

def find_view model_name
  @views.each do |v|
    if v.name == model_name
      return v
    end
  end
  nil
end

#generate(path = "#{@root.path}/project.xls") ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ld/project/structure.rb', line 13

def generate path = "#{@root.path}/project.xls"
  Ld::Excel.create path do |excel|
    # sheet.set_format({color: :black, font_size: 14, font: '微软雅黑'})
    excel.write_sheet 'routes' do |sheet|
      @routes = parse_routes @root
      sheet.set_headings @routes[:headings]
      sheet.set_rows @routes[:rows]
    end
    excel.write_sheet 'tables' do |sheet|
      @tables = parse_schema @root
      sheet.set_headings @tables[:headings]
      sheet.set_rows @tables[:rows]
    end
    excel.write_sheet 'models' do |sheet|
      @models = parse_models @root
      sheet.set_headings @models[:headings]
      sheet.set_rows @models[:rows]
    end
  end
end