Class: Aladdin::Support::OneOfMatcher

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(routes) ⇒ OneOfMatcher

Creates a new matcher for routes.

Parameters:

  • routes (Array)

    array of static paths



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