Sha256: 0189e05bcd51646c20fad11565980794dda7767a77b8226ef1d55b975202ff98

Contents?: true

Size: 725 Bytes

Versions: 10

Compression:

Stored size: 725 Bytes

Contents

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

module RailsBestPractices
  module Checks
    # Check a model to make sure finders are on their own model.
    #
    # Implementation: check if :find is called by other model.
    class KeepFindersOnTheirOwnModelCheck < Check
      
      def interesting_nodes
        [:call]
      end

      def interesting_files
        MODLE_FILES
      end

      def evaluate_start(node)
        add_error "keep finders on their own model" if others_finder?(node)
      end

      private

      def others_finder?(node)
        [:find, :all, :first, :last].include? node.message and node.subject.node_type == :call and node.arguments.size > 1
      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/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.5.5 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.5.3 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.5.2 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.5.1 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.5.0 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.4.6 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.4.5 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.4.4 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
rails_best_practices-0.4.3 lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb