Sha256: 9d16213b62a758932ea132a0bf82b9fb00a5bf93ffa949213647349cf6927404

Contents?: true

Size: 1.85 KB

Versions: 14

Compression:

Stored size: 1.85 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 call to see if any method call 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
      def url
        "http://rails-bestpractices.com/posts/12-not-use-default-route-if-you-use-restful-design"
      end

      def interesting_nodes
        [:call]
      end

      def interesting_files
        ROUTE_FILE
      end

      # check all method calls, it just compare with rails default route
      #
      # rails2
      #
      #     s(:call, s(:lvar, :map), :connect,
      #       s(:arglist, s(:str, ":controller/:action/:id"))
      #     )
      #     s(:call, s(:lvar, :map), :connect,
      #       s(:arglist, s(:str, ":controller/:action/:id.:format"))
      #     )
      #
      # rails3
      #
      #     s(:call, nil, :match,
      #       s(:arglist, s(:str, ":controller(/:action(/:id(.:format)))"))
      #     )
      def start_call(node)
        if s(:call, s(:lvar, :map), :connect, s(:arglist, s(:str, ":controller/:action/:id"))) == node ||
           s(:call, s(:lvar, :map), :connect, s(:arglist, s(:str, ":controller/:action/:id.:format"))) == node ||
           s(:call, nil, :match, s(:arglist, s(:str, ":controller(/:action(/:id(.:format)))"))) == node
          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-0.10.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.10.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-raydog153-0.9.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.9.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.8.2 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.8.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.8.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.7.5 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.7.4 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.7.3 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.7.2 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.7.1 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.7.0 lib/rails_best_practices/reviews/not_use_default_route_review.rb
rails_best_practices-0.6.7 lib/rails_best_practices/reviews/not_use_default_route_review.rb