Sha256: e1aeed923e29b3d2ee4f6d7e7dd4e4022d820bed054a02d5a01ebcf21a17f5ec
Contents?: true
Size: 872 Bytes
Versions: 34
Compression:
Stored size: 872 Bytes
Contents
require 'rails_best_practices/checks/check' module RailsBestPractices module Checks # Check a controller file to make sure finder is simple. # # Complex finder in controller is a code smell, use namd_scope instead. # # Implementation: check method :find, :all, :first, :last with hash parameters. class MoveFinderToNamedScopeCheck < Check FINDER = [:find, :all, :first, :last] def interesting_nodes [:call] end def interesting_files CONTROLLER_FILES end def evaluate_start(node) add_error "move finder to named_scope" if finder?(node) end private def finder?(node) node.subject.node_type == :const && FINDER.include?(node.message) && node.arguments.children.any? {|node| node.node_type == :hash} end end end end
Version data entries
34 entries across 34 versions & 1 rubygems