Sha256: 97a3eb43573616c309cc4ec9c824a6d2174d937750b7bc8b4f1983b6ad4a77b3

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

# encoding: utf-8
module RailsBestPractices
  module Reviews
    # Review config/routes file to make sure not use default route that rails generated.
    #
    # See the best practice details here http://rails-bestpractices.com/posts/2010/07/22/not-use-default-route-if-you-use-restful-design/
    #
    # Implementation:
    #
    # Review process:
    #   check all method command_call or command node to see if it is the same as rails default route.
    #
    #     map.connect ':controller/:action/:id'
    #     map.connect ':controller/:action/:id.:format'
    #
    #   or
    #
    #     match ':controller(/:action(/:id(.:format)))'
    class NotUseDefaultRouteReview < Review
      interesting_nodes :command_call, :command
      interesting_files ROUTE_FILES
      url "http://rails-bestpractices.com/posts/2010/07/22/not-use-default-route-if-you-use-restful-design/"

      # check all command call nodes, compare with rails2 default route
      add_callback :start_command_call do |node|
        if "map" == node.receiver.to_s && "connect" == node.message.to_s &&
          (":controller/:action/:id" == node.arguments.all.first.to_s ||
           ":controller/:action/:id.:format" == node.arguments.all.first.to_s)
          add_error "not use default route"
        end
      end

      # check all command nodes, compare with rails3 default route
      add_callback :start_command do |node|
        if "match" == node.message.to_s &&
          ":controller(/:action(/:id(.:format)))" == node.arguments.all.first.to_s
          add_error "not use default route"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails_best_practices-1.18.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.18.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.17.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.16.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.15.7 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.15.6 lib/rails_best_practices/reviews/not_use_default_route_review.rb