Sha256: b0e9eb5682767d370aee9c17a2a2597d42a613b3e5ecd0cce158852276a31400

Contents?: true

Size: 1.6 KB

Versions: 14

Compression:

Stored size: 1.6 KB

Contents

# encoding: utf-8
require 'rails_best_practices/reviews/review'

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/12-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

      def url
        "http://rails-bestpractices.com/posts/12-not-use-default-route-if-you-use-restful-design"
      end

      # check all command call nodes, compare with rails2 default route
      def start_command_call(node)
        if "map" == node.subject.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
      def start_command(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

14 entries across 14 versions & 2 rubygems

Version Path
rails_best_practices-1.10.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-gorgeouscode-1.0.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.10.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.9.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.9.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.8.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.7.2 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.7.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.7.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.6.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.5.3 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.5.2 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.5.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-1.5.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb