class RailsBestPractices::Reviews::OveruseRouteCustomizationsReview
Review
config/routes.rb file to make sure there are no overuse route customizations.
See the best practice details here rails-bestpractices.com/posts/2010/07/22/overuse-route-customizations/
Implementation:
Review
process:
check all method_add_block nodes in route file. if the receiver of method_add_block node is with message resources, and in the block body of method_add_block node, there are more than @customize_count command nodes, whose message is get, post, update or delete, then these custom routes are overuse.
Constants
- VERBS
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
# File lib/rails_best_practices/reviews/overuse_route_customizations_review.rb, line 25 def initialize(options = {}) super(options) @customize_count = options['customize_count'] || 3 end
Private Instance Methods
member_and_collection_count_for_rails3(node)
click to toggle source
check method_add_block node to calculate the count of member and collection custom routes.
if its receiver is with message “resources”, then calculate the count of call nodes, whose message is get, post, update or delete, it is just the count of member and collection custom routes.
# File lib/rails_best_practices/reviews/overuse_route_customizations_review.rb, line 49 def member_and_collection_count_for_rails3(node) node[1].message.to_s == 'resources' ? node.grep_nodes_count(sexp_type: :command, message: VERBS) : 0 end