class RailsBestPractices::Reviews::KeepFindersOnTheirOwnModelReview
Review
model files to make sure finders are on their own model.
See the best practice details here rails-bestpractices.com/posts/2010/07/23/keep-finders-on-their-own-model/
Implementation:
Review
process:
check all call nodes in model files. if the call node is a finder (find, all, first or last), and the it calls the other model, and there is a hash argument for finder, then it should keep finders on its own model.
Constants
- FINDERS
Private Instance Methods
other_finder?(node)
click to toggle source
check if the call node is the finder of other model.
the message of the node should be one of find, all, first or last, and the receiver of the node should be with message :call (this is the other model), and any of its arguments is a hash, then it is the finder of other model.
# File lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb, line 46 def other_finder?(node) FINDERS.include?(node[1].message.to_s) && node[1].receiver.sexp_type == :call && node.arguments.grep_nodes_count(sexp_type: :bare_assoc_hash) > 0 end