Class: RailsBestPractices::Reviews::SimplifyRenderInControllersReview

Inherits:
Review
  • Object
show all
Defined in:
lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb

Overview

Review a controller file to make sure using simplified syntax for render.

See the best practice details here rails-bestpractices.com/posts/62-simplify-render-in-controllers.

Implementation:

Review process:

check all render method calls in controller files,
if there is a key 'action', 'template' or 'file' in the argument,
then they should be replaced by simplified syntax.

Constant Summary

Constants inherited from Core::Check

Core::Check::CONTROLLER_FILES, Core::Check::HELPER_FILES, Core::Check::MAILER_FILES, Core::Check::MIGRATION_FILES, Core::Check::MODEL_FILES, Core::Check::NODE_TYPES, Core::Check::PARTIAL_VIEW_FILES, Core::Check::ROUTE_FILE, Core::Check::SCHEMA_FILE, Core::Check::VIEW_FILES

Instance Attribute Summary

Attributes inherited from Core::Check

#errors

Instance Method Summary collapse

Methods inherited from Review

#equal?, #model_associations, #model_attributes, #models, #remember_variable_use_count, #reset_variable_use_count, #variable, #variable_use_count

Methods inherited from Core::Check

#add_error, #initialize, #method_missing, #node_end, #node_start

Constructor Details

This class inherits a constructor from RailsBestPractices::Core::Check

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsBestPractices::Core::Check

Instance Method Details

#interesting_filesObject



25
26
27
# File 'lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb', line 25

def interesting_files
  CONTROLLER_FILES
end

#interesting_nodesObject



21
22
23
# File 'lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb', line 21

def interesting_nodes
  [:call]
end

#start_call(call_node) ⇒ Object

check call 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.



32
33
34
35
36
# File 'lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb', line 32

def start_call(call_node)
  if :render == call_node.message && call_node.arguments[1].to_s =~ /"(action|template|file)" =>/
    add_error 'simplify render in controllers'
  end
end

#urlObject



17
18
19
# File 'lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb', line 17

def url
  "http://rails-bestpractices.com/posts/62-simplify-render-in-controllers"
end