Skip to content

Commit

Permalink
Remove dupplication with logic.
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
  • Loading branch information
Jack12816 committed May 14, 2020
1 parent 9b1512b commit e350198
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/grape/api/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def cascade?
# cannot handle.
#
# rubocop:disable Metrics/AbcSize because of the complex workflow
# rubocop:disable Metrics/MethodLength dito
def add_head_not_allowed_methods_and_options_methods
routes_map = {}

Expand All @@ -207,11 +208,12 @@ def add_head_not_allowed_methods_and_options_methods
route_settings[:requirements] = route.requirements
route_settings[:path] = route.origin
route_settings[:methods] ||= []
route_settings[:methods] << route.request_method
if route.request_method == '*' || route_settings[:methods].include?('*')
route_settings[:methods] = Grape::Http::Headers::SUPPORTED_METHODS
else
route_settings[:methods] << route.request_method
end
route_settings[:endpoint] = route.app

# using the :any shorthand produces [nil] for route methods, substitute all manually
route_settings[:methods] = Grape::Http::Headers::SUPPORTED_METHODS.dup if route_settings[:methods].include?('*')
end
end

Expand Down Expand Up @@ -242,6 +244,7 @@ def add_head_not_allowed_methods_and_options_methods
end
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength

# Generate a route that returns an HTTP 405 response for a user defined
# path on methods not specified
Expand Down

0 comments on commit e350198

Please sign in to comment.