lib/grape/router.rb in grape-0.16.1 vs lib/grape/router.rb in grape-0.16.2

- old
+ new

@@ -39,11 +39,12 @@ @neutral_map << Any.new(pattern, options.merge(regexp: regexp, index: @neutral_map.length)) end def call(env) with_optimization do - identity(env) || rotation(env) { |route| route.exec(env) } + response, route = identity(env) + response || rotation(env, route) end end def recognize_path(input) any = with_optimization { greedy_match?(input) } @@ -52,30 +53,32 @@ end private def identity(env) - transaction(env) do |input, method, routing_args| + route = nil + response = transaction(env) do |input, method, routing_args| route = match?(input, method) if route env[Grape::Env::GRAPE_ROUTING_ARGS] = make_routing_args(routing_args, route, input) route.exec(env) end end + [response, route] end - def rotation(env) - transaction(env) do |input, method, routing_args| - response = nil - routes_for(method).each do |route| - next unless route.match?(input) - env[Grape::Env::GRAPE_ROUTING_ARGS] = make_routing_args(routing_args, route, input) - response = yield(route) - break unless cascade?(response) - end - response + def rotation(env, exact_route = nil) + response = nil + input, method, routing_args = *extract_required_args(env) + routes_for(method).each do |route| + next if exact_route == route + next unless route.match?(input) + env[Grape::Env::GRAPE_ROUTING_ARGS] = make_routing_args(routing_args, route, input) + response = route.exec(env) + break unless cascade?(response) end + response end def transaction(env) input, method, routing_args = *extract_required_args(env) response = yield(input, method, routing_args) @@ -120,13 +123,15 @@ last_match = Regexp.last_match @neutral_map.detect { |route| last_match["_#{route.index}"] } end def method_not_allowed(env, methods, endpoint) + env[Grape::Env::GRAPE_METHOD_NOT_ALLOWED] = true current = endpoint.dup current.instance_eval do + @lazy_initialized = false + lazy_initialize! run_filters befores, :before - @method_not_allowed = true @block = proc do fail Grape::Exceptions::MethodNotAllowed, header.merge('Allow' => methods) end end current.call(env)