Sha256: 578b2915b009e68b0abb7494a79d38542ffde5c6a4a900baf455c402548dd3a1

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8
module RailsBestPractices
  module Reviews
    # Review a controller file to make sure using simplified syntax for render.
    #
    # See the best practice details here http://rails-bestpractices.com/posts/2010/12/12/simplify-render-in-controllers/
    #
    # Implementation:
    #
    # Review process:
    #   check all render method commands in controller files,
    #   if there is a key 'action', 'template' or 'file' in the argument,
    #   then they should be replaced by simplified syntax.
    class SimplifyRenderInControllersReview < Review
      interesting_nodes :command
      interesting_files CONTROLLER_FILES
      url "http://rails-bestpractices.com/posts/2010/12/12/simplify-render-in-controllers/"

      # check command node in the controller file,
      # if its message is render and the arguments contain a key action, template or file,
      # then it should be replaced by simplified syntax.
      add_callback :start_command do |node|
        if "render" == node.message.to_s
          keys = node.arguments.all.first.hash_keys
          if keys && keys.size == 1 &&
             (keys.include?("action") || keys.include?("template") || keys.include?("file"))
            add_error 'simplify render in controllers'
          end
        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/simplify_render_in_controllers_review.rb
rails_best_practices-1.18.0 lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb
rails_best_practices-1.17.0 lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb
rails_best_practices-1.16.0 lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb
rails_best_practices-1.15.7 lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb
rails_best_practices-1.15.6 lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb