Class: Aladdin::Support::OneOfMatcher
- Inherits:
-
Object
- Object
- Aladdin::Support::OneOfMatcher
- Defined in:
- lib/aladdin/support/multiroute.rb
Overview
Sinatra route matcher that matches mutltiple paths given in an array.
Defined Under Namespace
Classes: Match
Instance Method Summary collapse
-
#initialize(routes) ⇒ OneOfMatcher
constructor
Creates a new matcher for
routes
. -
#match(str) ⇒ Object
Matches
routes
againststr
.
Constructor Details
#initialize(routes) ⇒ OneOfMatcher
Creates a new matcher for routes
.
13 14 15 16 |
# File 'lib/aladdin/support/multiroute.rb', line 13 def initialize(routes) @routes = routes.map { |r| '/' + r } @captures = Match.new [] end |
Instance Method Details
#match(str) ⇒ Object
Matches routes
against str
.
19 20 21 22 |
# File 'lib/aladdin/support/multiroute.rb', line 19 def match(str) @captures[:captures] = [str] @captures if @routes.any? { |r| str.starts_with? r } end |