class Amber::Router::RouteSet(T)
- Amber::Router::RouteSet(T)
- Reference
- Object
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 TerminalSegment
s.
route_set = Amber::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
route_set.add "/get/posts/:page", :pages, {"page" => /\d+/}
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
route_set.find("/get/posts/123").found? # => true
route_set.find("/get/posts/one").found? # => false
Defined in:
amber_router/route_set.crConstructors
Instance Method Summary
-
#add(path, payload : T, constraints : Hash(String, Regex) = {} of String => Regex) : Nil
Add a route to the tree.
-
#add(path, payload : T, constraints : Hash(Symbol, Regex) | NamedTuple) : Nil
ditto
-
#find(path : String) : RoutedResult(T)
Find a route which is compatible with a path.
-
#find_routes(path : String) : Array(RoutedResult(T))
Returns the routes which are compatible with the provided path.
-
#formatted_s(*, ts = 0)
Produces a readable, indented rendering of the tree.
- #routes? : Bool
Constructor Detail
Instance Method Detail
Add a route to the tree.
def find_routes(path : String) : Array(RoutedResult(T))
#
Returns the routes which are compatible with the provided path.