Class: RuboCop::Cop::Grape::UnnecessaryNamespace
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Grape::UnnecessaryNamespace
- Defined in:
- lib/rubocop/cop/grape/unnecessary_namespace.rb
Overview
Detect unnecessary usage of Grape namespace.
# bad
namespace :some_path do
get {}
end
# good
get :some_path {}
Constant Summary collapse
- MSG =
'Unnecessary usage of Grape namespace. ' \ 'Specify endpoint name with an argument: `get :some_path`.'
- HTTP_ACTIONS =
Set.new(%i[get head put post patch delete])
- GRAPE_NAMESPACE_ALIAS =
Set.new(%i[namespace resource resources])
- METHOD_JUSTIFY_NAMESPACE =
Set.new(%i[route_param namespaces resource resources version])
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cop/grape/unnecessary_namespace.rb', line 39 def on_send(node) return unless namespace?(node) node_to_select_http_action = namespace_node(node) return if node_to_select_http_action.any? do |namespace_node| justify_namespace?(namespace_node) end http_action_node = select_http_action_block_node(node_to_select_http_action) return if http_action_node.size != 1 paths = paths_added_with_http_action(http_action_node.first) add_offense(node) if paths.empty? end |