Class: RuboCop::Cop::Rails::MatchRoute
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::MatchRoute
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rails/match_route.rb
Overview
Identifies places where defining routes with ‘match` can be replaced with a specific HTTP method.
Don’t use ‘match` to define any routes unless there is a need to map multiple request types among [:get, :post, :patch, :put, :delete] to a single action using the `:via` option.
Constant Summary collapse
- MSG =
'Use `%<http_method>s` instead of `match` to define a route.'
- RESTRICT_ON_SEND =
%i[match].freeze
- HTTP_METHODS =
%i[get post put patch delete].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubocop/cop/rails/match_route.rb', line 34 def on_send(node) match_method_call?(node) do |path_node, | return unless within_routes?(node) = path_node.hash_type? ? path_node : .first if .nil? register_offense(node, 'get') else via = extract_via() return unless via.size == 1 && http_method?(via.first) register_offense(node, via.first) end end end |