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

Version Path
rails_best_practices-0.3.10 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.9 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.8 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.7 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.6 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.5 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.4 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.3 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.2 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.1 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.0 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.16 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.15 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.14 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb