lib/grape/router.rb in grape-0.17.0 vs lib/grape/router.rb in grape-0.18.0

- old
+ new

@@ -3,11 +3,11 @@ module Grape class Router attr_reader :map, :compiled class Any < AttributeTranslator - def initialize(pattern, attributes = {}) + def initialize(pattern, **attributes) @pattern = pattern super(attributes) end end @@ -40,13 +40,13 @@ def append(route) map[route.request_method.to_s.upcase] << route end - def associate_routes(pattern, options = {}) + def associate_routes(pattern, **options) regexp = /(?<_#{@neutral_map.length}>)#{pattern.to_regexp}/ - @neutral_map << Any.new(pattern, options.merge(regexp: regexp, index: @neutral_map.length)) + @neutral_map << Any.new(pattern, regexp: regexp, index: @neutral_map.length, **options) end def call(env) with_optimization do response, route = identity(env) @@ -93,11 +93,11 @@ return response if response && !(cascade = cascade?(response)) neighbor = greedy_match?(input) return unless neighbor - (!cascade && neighbor) ? method_not_allowed(env, neighbor.allow_header, neighbor.endpoint) : nil + (!cascade && neighbor) ? call_with_allow_headers(env, neighbor.allow_header, neighbor.endpoint) : nil end def make_routing_args(default_args, route, input) args = default_args || { route_info: route } args.merge(route.params(input)) @@ -130,11 +130,11 @@ return unless @union.match(input) 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] = methods + def call_with_allow_headers(env, methods, endpoint) + env[Grape::Env::GRAPE_ALLOWED_METHODS] = methods endpoint.call(env) end def cascade?(response) response && response[1][Grape::Http::Headers::X_CASCADE] == 'pass'