Skip to content

Commit

Permalink
Use regex block instead of if (#2383)
Browse files Browse the repository at this point in the history
* Use regex block instead of if

* fix rubocop space + CHANGELOG.md

---------

Co-authored-by: Daniel (dB.) Doubrovkine <dblock@dblock.org>
  • Loading branch information
ericproulx and dblock authored Dec 12, 2023
1 parent 4e3b5fd commit 0456797
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

* [#2371](https://github.com/ruby-grape/grape/pull/2371): Use a param value as the `default` value of other param - [@jcagarcia](https://github.com/jcagarcia).
* [#2377](https://github.com/ruby-grape/grape/pull/2377): Allow to use instance variables values inside `rescue_from` - [@jcagarcia](https://github.com/jcagarcia).
* [#2379](https://github.com/ruby-grape/grape/pull/2379): `recognize_path` now takes into account the `route_param` type - [@jcagarcia](https://github.com/jcagarcia).
* [#2379](https://github.com/ruby-grape/grape/pull/2379): Take into account the `route_param` type in `recognize_path` - [@jcagarcia](https://github.com/jcagarcia).
* [#2383](https://github.com/ruby-grape/grape/pull/2383): Use regex block instead of if - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
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 0456797

Please sign in to comment.