lib/grape/router.rb in grape-1.5.3 vs lib/grape/router.rb in grape-1.6.0

- old
+ new

@@ -26,10 +26,11 @@ @optimized_map = Hash.new { |hash, key| hash[key] = // } end def compile! return if compiled + @union = Regexp.union(@neutral_regexes) @neutral_regexes = nil self.class.supported_methods.each do |method| routes = map[method] @optimized_map[method] = routes.map.with_index do |route, index| @@ -58,10 +59,11 @@ end def recognize_path(input) any = with_optimization { greedy_match?(input) } return if any == default_response + any.endpoint end private @@ -78,10 +80,11 @@ response = nil input, method = *extract_input_and_method(env) map[method].each do |route| next if exact_route == route next unless route.match?(input) + response = process_route(route, env) break unless cascade?(response) end response end @@ -89,10 +92,11 @@ def transaction(env) input, method = *extract_input_and_method(env) response = yield(input, method) return response if response && !(cascade = cascade?(response)) + last_neighbor_route = greedy_match?(input) # If last_neighbor_route exists and request method is OPTIONS, # return response by using #call_with_allow_headers. return call_with_allow_headers(env, last_neighbor_route) if last_neighbor_route && method == Grape::Http::Headers::OPTIONS && !cascade @@ -137,15 +141,17 @@ 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}"] } end def greedy_match?(input) return unless @union.match(input) + last_match = Regexp.last_match @neutral_map.detect { |route| last_match["_#{route.index}"] } end def call_with_allow_headers(env, route)