Class: RailsBestPractices::Reviews::MoveFinderToNamedScopeReview
- Inherits:
-
Review
- Object
- Core::Check
- Review
- RailsBestPractices::Reviews::MoveFinderToNamedScopeReview
- Defined in:
- lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb
Overview
Review a controller file to make sure there are no complex finder.
See the best practice details here rails-bestpractices.com/posts/1-move-finder-to-named_scope.
Implementation:
Review process:
check all method calls in controller files.
if there is any call node with message find, all, first or last,
and it has a hash argument,
then it is a complex finder, and should be moved to model's named scope.
Constant Summary collapse
- FINDER =
[: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 call node if its message is one of :find, :all, :first or :last, and it has a hash argument, then the call node is the finder that should be moved to model’s named_scope.
- #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
29 30 31 |
# File 'lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb', line 29 def interesting_files CONTROLLER_FILES end |
#interesting_nodes ⇒ Object
25 26 27 |
# File 'lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb', line 25 def interesting_nodes [:call] end |
#start_call(node) ⇒ Object
check call node if its message is one of :find, :all, :first or :last, and it has a hash argument, then the call node is the finder that should be moved to model’s named_scope.
36 37 38 |
# File 'lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb', line 36 def start_call(node) add_error "move finder to named_scope" if finder?(node) end |
#url ⇒ Object
21 22 23 |
# File 'lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb', line 21 def url "http://rails-bestpractices.com/posts/1-move-finder-to-named_scope" end |