Method: Grape::Router#compile!

Defined in:
lib/grape/router.rb

#compile!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/grape/router.rb', line 37

def compile!
  return if compiled
  @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 = Regexp.new("(?<_#{index}>#{route.pattern.to_regexp})")
    end
    @optimized_map[method] = Regexp.union(@optimized_map[method])
  end
  @compiled = true
end