Class: Kawaii::StringMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/matchers.rb

Overview

Matcher for string paths. Supports named params.

Examples:

Simple string matcher

get '/users' do ... end

Named parameters

get '/users/:id' do ... end

Wildcards

get '/users/?' do ... end # Optional trailing slash

Instance Method Summary (collapse)

Constructor Details

- (StringMatcher) initialize(path)

Parameters:

  • path (String)

    path specification



67
68
69
# File 'lib/kawaii/matchers.rb', line 67

def initialize(path)
  @rx = compile(path)
end

Instance Method Details

- (Match) match(path)

Tries to match the actual path. is no match.

Parameters:

  • path (String)

    the actual path from Rack env

Returns:

  • (Match)

    if the beginning of path does match or nil if there



75
76
77
78
# File 'lib/kawaii/matchers.rb', line 75

def match(path)
  m = path.match(@rx)
  Match.new(remaining_path(path, m), match_to_params(m)) if m
end