Sha256: dde8fd1955902141dde9464f287d889116cacbced9d2706dd2420295a3ecb051

Contents?: true

Size: 932 Bytes

Versions: 44

Compression:

Stored size: 932 Bytes

Contents

require 'rails_best_practices/checks/check'

module RailsBestPractices
  module Checks
    # 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.
    class NeedlessDeepNestingCheck < Check
      
      def interesting_nodes
        [:call]
      end

      def interesting_files
        /config\/routes.rb/
      end

      def initialize(options = {})
        super()
        @nested_count = options['nested_count'] || 2
      end
      
      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
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
rails_best_practices-0.2.3 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.2.2 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.2.1 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.2.0 lib/rails_best_practices/checks/needless_deep_nesting_check.rb