Class: SimpleRouter::Engines::SimpleEngine
- Inherits:
-
Object
- Object
- SimpleRouter::Engines::SimpleEngine
- Defined in:
- lib/simple_router/engines/simple_engine.rb
Class Method Summary collapse
-
.match(path, routes) ⇒ Object
Finds a route definition that matches a path.
Class Method Details
.match(path, routes) ⇒ Object
Finds a route definition that matches a path
Arguments
-
path: actual path to match (e.g. ENV)
-
routes: array of user defined routes
Returns
Array of two elements:
-
index 0: first matching route
-
index 1: array of values for route variables, in the order they were specified
Examples
SimpleEngine.match('/foo', ['/', '/foo', '/bar/baz']) #=> ['/foo', []]
SimpleEngine.match('/80/07/01', ['/:year/:month/:day']) #=> ['/foo', ['80', '07', '01']]
22 23 24 25 26 27 |
# File 'lib/simple_router/engines/simple_engine.rb', line 22 def self.match(path, routes) routes.each do |route| return route if route == path end nil end |