Skip to content

Commit

Permalink
Use regex block instead of if
Browse files Browse the repository at this point in the history
  • Loading branch information
ericproulx committed Dec 9, 2023
1 parent 34f90f8 commit bd312f9
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,11 @@ def default_response
end

def match?(input, method)
current_regexp = @optimized_map[method]
return unless current_regexp.match(input)

last_match = Regexp.last_match
@map[method].detect { |route| last_match["_#{route.index}"] }
@optimized_map[method].match(input) { |m| @map[method].detect { |route| m["_#{route.index}"] } }
end

def greedy_match?(input)
return unless @union.match(input)

last_match = Regexp.last_match
@neutral_map.detect { |route| last_match["_#{route.index}"] }
@union.match(input) { |m| @neutral_map.detect { |route| m["_#{route.index}"] } }
end

def call_with_allow_headers(env, route)
Expand Down

0 comments on commit bd312f9

Please sign in to comment.