Class: RuboCop::Cop::Guardrails::RestfulActions
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Guardrails::RestfulActions
- Includes:
- VisibilityHelpers
- Defined in:
- lib/rubocop/cop/guardrails/restful_actions.rb
Overview
Prevents non-RESTful actions in controllers.
Rails advocates for RESTful resources. When you need a custom action, extract a new controller with standard RESTful actions.
Constant Summary collapse
- MSG =
'Non-RESTful action `%<method>s`. Add a new resource to represent this action.'- RESTFUL_ACTIONS =
%i[index show new create edit update destroy].to_set.freeze
Instance Method Summary collapse
Instance Method Details
#on_def(node) ⇒ Object
30 31 32 33 34 |
# File 'lib/rubocop/cop/guardrails/restful_actions.rb', line 30 def on_def(node) if !RESTFUL_ACTIONS.include?(node.method_name) && in_class?(node) && public_method?(node) add_offense(node.loc.name, message: format(MSG, method: node.method_name)) end end |