diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab7a42b35..c91454a959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/grape/router.rb b/lib/grape/router.rb index 691889cd60..3c4142b38c 100644 --- a/lib/grape/router.rb +++ b/lib/grape/router.rb @@ -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)