Sha256: 3893ea5b29a59b74c8542f738e4d0c72d7015d5e65f136f4cf3ca103d6cef41d

Contents?: true

Size: 748 Bytes

Versions: 10

Compression:

Stored size: 748 Bytes

Contents

# encoding: utf-8
require 'rails_best_practices/checks/check'

module RailsBestPractices
  module Checks
    # Check a view file to make sure there is no finder.
    #
    # Implementation: Check if view file contains finder, then the code should move to controller.
    class MoveCodeIntoControllerCheck < Check
      
      FINDER = [:find, :all, :first, :last]
      
      def interesting_nodes
        [:call]
      end
      
      def interesting_files
        VIEW_FILES
      end
      
      def evaluate_start(node)
        add_error "move code into controller" if finder?(node)
      end
      
      private

      def finder?(node)
        node.subject.node_type == :const && FINDER.include?(node.message)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails_best_practices-0.5.6 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.5.5 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.5.3 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.5.2 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.5.1 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.5.0 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.4.6 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.4.5 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.4.4 lib/rails_best_practices/checks/move_code_into_controller_check.rb
rails_best_practices-0.4.3 lib/rails_best_practices/checks/move_code_into_controller_check.rb