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.4.2 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.4.1 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.4.0 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.27 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.26 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.25 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.24 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.23 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.22 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.21 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.20 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.19 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.18 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.17 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.16 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.15 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.14 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.13 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.12 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
rails_best_practices-0.3.11 lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb