Sha256: 66367b4c0861c08d09a562c062654ed60c3813ce1dd5bf572d9a10f9de3ca5e8

Contents?: true

Size: 873 Bytes

Versions: 16

Compression:

Stored size: 873 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.rb$/
      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

16 entries across 16 versions & 1 rubygems

Version Path
rails_best_practices-0.2.13 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.12 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.11 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.10 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.9 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.8 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.6 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.5 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.4 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.3 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.2 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.1 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.2.0 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.1.2 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.1.1 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.1.0 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb