Class: Ld::Controllers
- Inherits:
-
Object
- Object
- Ld::Controllers
- Defined in:
- lib/ld/project/controllers.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
- #find_controller(model_name) ⇒ Object
-
#initialize(root, models) ⇒ Controllers
constructor
A new instance of Controllers.
- #parse ⇒ Object
- #parse_by_model_name(model_name) ⇒ Object
Constructor Details
#initialize(root, models) ⇒ Controllers
Returns a new instance of Controllers.
5 6 7 8 9 |
# File 'lib/ld/project/controllers.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/controllers.rb', line 3 def headings @headings end |
#rows ⇒ Object
Returns the value of attribute rows.
3 4 5 |
# File 'lib/ld/project/controllers.rb', line 3 def rows @rows end |
Instance Method Details
#find_controller(model_name) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/ld/project/controllers.rb', line 31 def find_controller model_name @controllers.each do |c| if c.name.split('_controller.rb')[0] == model_name return c end end nil end |
#parse ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ld/project/controllers.rb', line 11 def parse @rows = @root.find('app/controllers').search_regexp(/_controller.rb$/).map { |c| model_name = c.name.split('_controller')[0].singularize model_name = @models.models.include?(model_name) ? model_name : nil lines = c.lines actions = lines.map{|l| l.split('def ')[1] if l.match(/def /)}.compact [model_name, c.name,actions.size, lines.size, c.path,actions.join(',')] }.sort{|a,b| b[2] <=> a[2]} @headings = ['所属模型名称', '控制器名','action个数', '文件行数','path', '所有action'] end |
#parse_by_model_name(model_name) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/ld/project/controllers.rb', line 22 def parse_by_model_name model_name controller = find_controller model_name.pluralize if controller controller_lines = controller.lines controller_methods = controller_lines.map{|l| l.split('def ')[1].chomp if l.match(/def /)}.compact end controller end |