lib/grape/router.rb in grape-1.2.5 vs lib/grape/router.rb in grape-1.3.0
- old
+ new
@@ -1,20 +1,25 @@
+# frozen_string_literal: true
+
require 'grape/router/route'
module Grape
class Router
attr_reader :map, :compiled
class Any < AttributeTranslator
- def initialize(pattern, **attributes)
+ attr_reader :pattern, :regexp, :index
+ def initialize(pattern, regexp, index, **attributes)
@pattern = pattern
+ @regexp = regexp
+ @index = index
super(attributes)
end
end
def self.normalize_path(path)
- path = "/#{path}"
+ path = +"/#{path}"
path.squeeze!('/')
path.sub!(%r{/+\Z}, '')
path = '/' if path == ''
path
end
@@ -34,23 +39,23 @@
@union = Regexp.union(@neutral_map.map(&:regexp))
self.class.supported_methods.each do |method|
routes = map[method]
@optimized_map[method] = routes.map.with_index do |route, index|
route.index = index
- route.regexp = /(?<_#{index}>#{route.pattern.to_regexp})/
+ route.regexp = Regexp.new("(?<_#{index}>#{route.pattern.to_regexp})")
end
@optimized_map[method] = Regexp.union(@optimized_map[method])
end
@compiled = true
end
def append(route)
- map[route.request_method.to_s.upcase] << route
+ map[route.request_method] << route
end
def associate_routes(pattern, **options)
- regexp = /(?<_#{@neutral_map.length}>)#{pattern.to_regexp}/
- @neutral_map << Any.new(pattern, regexp: regexp, index: @neutral_map.length, **options)
+ regexp = Regexp.new("(?<_#{@neutral_map.length}>)#{pattern.to_regexp}")
+ @neutral_map << Any.new(pattern, regexp, @neutral_map.length, **options)
end
def call(env)
with_optimization do
response, route = identity(env)