Class: RailsBestPractices::Reviews::RestrictAutoGeneratedRoutesReview
- Inherits:
-
Review
- Object
- CodeAnalyzer::Checker
- Core::Check
- Review
- RailsBestPractices::Reviews::RestrictAutoGeneratedRoutesReview
- Defined in:
- lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb
Overview
Review a route file to make sure all auto-generated routes have corresponding actions in controller.
See the best practice details here rails-bestpractices.com/posts/2011/08/19/restrict-auto-generated-routes/
Implementation:
Review process:
check all resources and resource method calls,
compare the generated routes and corresponding actions in controller,
if there is a route generated, but there is not action in that controller,
then you should restrict your routes.
Constant Summary
Constants inherited from Core::Check
Core::Check::ALL_FILES, Core::Check::CAPFILE, Core::Check::CONFIG_FILES, Core::Check::CONTROLLER_FILES, Core::Check::DEPLOY_FILES, Core::Check::GEMFILE_LOCK, Core::Check::HELPER_FILES, Core::Check::INITIALIZER_FILES, Core::Check::MAILER_FILES, Core::Check::MIGRATION_FILES, Core::Check::MODEL_FILES, Core::Check::PARTIAL_VIEW_FILES, Core::Check::ROUTE_FILES, Core::Check::SCHEMA_FILE, Core::Check::SKIP_FILES, Core::Check::VIEW_FILES
Instance Method Summary collapse
- #check_method_add_block?(node) ⇒ Boolean
-
#initialize(options = {}) ⇒ RestrictAutoGeneratedRoutesReview
constructor
A new instance of RestrictAutoGeneratedRoutesReview.
- #resource_methods ⇒ Object
- #resources_methods ⇒ Object
Methods inherited from Review
#model_associations, #model_attributes, #models, #remember_variable_use_count, #reset_variable_use_count, #variable, #variable_use_count
Methods inherited from Core::Check
#add_error, debug, debug?, #errors, #is_ignored?, #is_interesting_file?, #method_missing, #parse_file?, #regex_ignored_files, #url, url
Constructor Details
#initialize(options = {}) ⇒ RestrictAutoGeneratedRoutesReview
Returns a new instance of RestrictAutoGeneratedRoutesReview.
33 34 35 36 37 |
# File 'lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb', line 33 def initialize( = {}) super() @namespaces = [] @resource_controllers = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsBestPractices::Core::Check
Instance Method Details
#check_method_add_block?(node) ⇒ Boolean
92 93 94 |
# File 'lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb', line 92 def check_method_add_block?(node) node[1].sexp_type == :command || (node[1].sexp_type == :command_call && node.receiver.to_s != 'map') end |
#resource_methods ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb', line 21 def resource_methods if Prepares.configs['config.api_only'] %w[show create update destroy] else %w[show new create edit update destroy] end end |
#resources_methods ⇒ Object
29 30 31 |
# File 'lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb', line 29 def resources_methods resource_methods + ['index'] end |