class Maze::Router::RouteSet(T)

Overview

A tree which stores and navigates routes associated with a web application.

A route set represents the branches of the tree, and each vertex is a Segment. Leaf nodes are TerminalSegments.

route_set = Maze::Router::RouteSet(Symbol).new
route_set.add "/get/", :root
route_set.add "/get/users/:id", :users
route_set.add "/get/users/:id/books", :users_books
route_set.add "/get/*/slug", :slug
route_set.add "/get/*", :catch_all

p route_set.formatted_s # => a textual representation of the routing tree

route_set.find("/get/users/3").payload           # => :users
route_set.find("/get/users/3/books").payload     # => :users_books
route_set.find("/get/coffee_maker/slug").payload # => :slug
route_set.find("/get/made/up/url").payload       # => :catch_all

Defined in:

maze/router/route_set.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(root : Bool = true) #

[View source]

Instance Method Detail

def add(path, payload : T) : Nil #

Add a route to the tree.


[View source]
def find(path : String) : RoutedResult(T) #

Find a route which is compatible with a path.


[View source]
def formatted_s(*, ts = 0) #

Produces a readable, indented rendering of the tree


[View source]
def routes? : Bool #

[View source]