Class: OpenapiRuby::Middleware::PathMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_ruby/middleware/path_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(path_templates) ⇒ PathMatcher

Returns a new instance of PathMatcher.



6
7
8
# File 'lib/openapi_ruby/middleware/path_matcher.rb', line 6

def initialize(path_templates)
  @matchers = build_matchers(path_templates)
end

Instance Method Details

#match(request_path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/openapi_ruby/middleware/path_matcher.rb', line 10

def match(request_path)
  @matchers.each do |template, pattern|
    match_data = pattern.match(request_path)
    next unless match_data

    path_params = match_data.named_captures.transform_values { |v| Rack::Utils.unescape(v) }
    return [template, path_params]
  end
  nil
end