Class: RailsBestPractices::Reviews::KeepFindersOnTheirOwnModelReview
- Inherits:
-
Review
- Object
- Core::Check
- Review
- RailsBestPractices::Reviews::KeepFindersOnTheirOwnModelReview
- Defined in:
- lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb
Overview
Review model files to ake sure finders are on their own model.
See the best practice details here rails-bestpractices.com/posts/13-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.
Constant Summary collapse
- FINDERS =
[:find, :all, :first, :last]
Constants inherited from Core::Check
Core::Check::CONTROLLER_FILES, Core::Check::HELPER_FILES, Core::Check::MAILER_FILES, Core::Check::MIGRATION_FILES, Core::Check::MODEL_FILES, Core::Check::NODE_TYPES, Core::Check::PARTIAL_VIEW_FILES, Core::Check::ROUTE_FILE, Core::Check::SCHEMA_FILE, Core::Check::VIEW_FILES
Instance Attribute Summary
Attributes inherited from Core::Check
Instance Method Summary collapse
- #interesting_files ⇒ Object
- #interesting_nodes ⇒ Object
-
#start_call(node) ⇒ Object
check all the call nodes to see if there is a finder for other model.
- #url ⇒ Object
Methods inherited from Review
#equal?, #model_associations, #model_attributes, #models, #remember_variable_use_count, #reset_variable_use_count, #variable, #variable_use_count
Methods inherited from Core::Check
#add_error, #initialize, #method_missing, #node_end, #node_start
Constructor Details
This class inherits a constructor from RailsBestPractices::Core::Check
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsBestPractices::Core::Check
Instance Method Details
#interesting_files ⇒ Object
31 32 33 |
# File 'lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb', line 31 def interesting_files MODEL_FILES end |
#interesting_nodes ⇒ Object
27 28 29 |
# File 'lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb', line 27 def interesting_nodes [:call] end |
#start_call(node) ⇒ Object
check all the call nodes to see if there is a finder for other model.
if the call node is
-
the message of call node is one of the :find, :all, :first or :last
-
the subject of call node is also a call node (it’s the other model)
-
the any of its arguments is a hash (complex finder)
then it should keep finders on its own model.
44 45 46 |
# File 'lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb', line 44 def start_call(node) add_error "keep finders on their own model" if other_finder?(node) end |
#url ⇒ Object
23 24 25 |
# File 'lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb', line 23 def url "http://rails-bestpractices.com/posts/13-keep-finders-on-their-own-model" end |