Class: Ld::Routes
- Inherits:
-
Object
- Object
- Ld::Routes
- Defined in:
- lib/ld/project/routes.rb
Instance Attribute Summary collapse
-
#headings ⇒ Object
Returns the value of attribute headings.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(root, models) ⇒ Routes
constructor
A new instance of Routes.
- #parse ⇒ Object
Constructor Details
#initialize(root, models) ⇒ Routes
5 6 7 8 9 |
# File 'lib/ld/project/routes.rb', line 5 def initialize root, models @root = root @models = models parse end |
Instance Attribute Details
#headings ⇒ Object
Returns the value of attribute headings.
3 4 5 |
# File 'lib/ld/project/routes.rb', line 3 def headings @headings end |
#rows ⇒ Object
Returns the value of attribute rows.
3 4 5 |
# File 'lib/ld/project/routes.rb', line 3 def rows @rows end |
Instance Method Details
#parse ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ld/project/routes.rb', line 11 def parse system "rake routes > #{@root.path}/routes.txt" if !File.exist? "#{@root.path}/routes.txt" @rows = @root.find('routes.txt').lines.map{|line| arr = line.split(' ') arr.unshift(nil) if arr.size == 3 arr }.delete_if{|arr| arr.size >= 5 or arr.size <= 2 }.map{|row| controller, action = row[3].split('#') controller_name = controller.split('/').last if @models @model_name = @models.models.include?(controller_name.singularize) ? controller_name.singularize : nil end type = row[1] help_method = row[0] uri = row[2] [@model_name,controller_name, action, type, uri, help_method] }.sort{|a,b| a[1] <=> b[1]} File.delete("#{@root.path}/routes.txt") if File.exist? "#{@root.path}/routes.txt" @headings = ['所属模型','控制器', 'action', '请求类型','URI','帮助方法'] end |