Parent

Files

RailsBestPractices::Checks::NeedlessDeepNestingCheck

Check config/routes.rb to make sure not to use too deep nesting routes.

Implementation: check nested route count, if more than nested_count, then it is needless deep nesting.

Public Class Methods

new(options = {}) click to toggle source
# File lib/rails_best_practices/checks/needless_deep_nesting_check.rb, line 18
def initialize(options = {})
  super()
  @nested_count = options['nested_count'] || 2
end

Public Instance Methods

evaluate_start(node) click to toggle source
# File lib/rails_best_practices/checks/needless_deep_nesting_check.rb, line 23
def evaluate_start(node)
  if node.message == :resources
    if node.subject == s(:call, nil, :map, s(:arglist))
      @counter = 0
    else
      @counter += 1
      add_error "needless deep nesting (nested_count > #{@nested_count})" if @counter >= @nested_count
    end
  end
end
interesting_files() click to toggle source
# File lib/rails_best_practices/checks/needless_deep_nesting_check.rb, line 14
def interesting_files
  /config\/routes.rb/
end
interesting_nodes() click to toggle source
# File lib/rails_best_practices/checks/needless_deep_nesting_check.rb, line 10
def interesting_nodes
  [:call]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.