Sha256: e78f8b5dc332f47aab845d0c56e3c1eb5ae308e01e20a17c5a6065d28b88c168
Contents?: true
Size: 1.19 KB
Versions: 34
Compression:
Stored size: 1.19 KB
Contents
require 'rails_best_practices/checks/check' module RailsBestPractices module Checks # Check config/routes.rb to make sure there are no much route customizations. # # Implementation: check member and collection route count, if more than customize_count, then it is overuse route customizations. class OveruseRouteCustomizationsCheck < Check def interesting_nodes [:call] end def interesting_files /config\/routes.rb/ end def initialize(options = {}) super() @customize_count = options['customize_count'] || 3 end def evaluate_start(node) if s(:lvar, :map) == node.subject and :resources == node.message add_error "overuse route customizations (customize_count > #{@customize_count})" if member_and_collection_count(node) > @customize_count end end private def member_and_collection_count(node) hash_nodes = node.grep_nodes(:node_type => :hash) return 0 if hash_nodes.empty? customize_hash = eval(hash_nodes.first.to_ruby) (customize_hash[:member].size || 0) + (customize_hash[:collection].size || 0) end end end end
Version data entries
34 entries across 34 versions & 1 rubygems