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.3.27 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.26 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.25 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.24 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.23 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.22 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.21 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.20 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.19 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.18 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.17 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.16 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.15 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.14 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.13 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.12 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.11 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.10 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.9 lib/rails_best_practices/checks/needless_deep_nesting_check.rb
rails_best_practices-0.3.8 lib/rails_best_practices/checks/needless_deep_nesting_check.rb