class Fossil::Router

Overview

Router class. A instance of a class is a node in a route tree.

Defined in:

router.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(path : Nil | String = nil, parameter : Nil | String = nil) #

Initializer for Router.


Instance Method Detail

def /(other : String) : self #

New Routers are implicitly created with calling a slash operator.

root = Fossil::Router.new ""
root / "route_a/its_child"
root / "route_b/@param1:int/info"

def children : Array(Router) #

Routers that may can go after self and do not start with a path parameter.


def children=(children : Array(Router)) #

Routers that may can go after self and do not start with a path parameter.


def endpoints : Hash(Fossil::MethodsEnum, Fossil::Endpoint) #

Endpoints at the route that is resolved to current Router.


def endpoints=(endpoints : Hash(Fossil::MethodsEnum, Fossil::Endpoint)) #

Endpoints at the route that is resolved to current Router.


def param_children : Hash(Fossil::Param::PathParamTypeEnum, Router) #

Routers that may can go after self and do start with a path parameter. Type of a parameter is a key in a Hash, so its capacity is equal to 3.


def param_children=(param_children : Hash(Fossil::Param::PathParamTypeEnum, Router)) #

Routers that may can go after self and do start with a path parameter. Type of a parameter is a key in a Hash, so its capacity is equal to 3.


def parameter : Nil | String #

Name of a path parameter a path that can be resolved to one of the endpoints down the tree from the current node starts with. While @path is a whole fragment between two slashes, @parameter is parsed from a fragment "@<parameter_name>:<parameter_type>", where <parameter_type> is of type Fossil::Param::PathParamTypeEnum (string that can be parsed to this enum).


def path : Nil | String #

The first path fragment of a path that can be resolved to one of the endpoints down the tree from the current node. If @path.is_nil the fragment is a path parameter.


def trace(path : String, path_params = {} of String => Fossil::Param::PathParamType) : Tuple(Router, Hash(String, Fossil::Param::PathParamType)) #

Trace #path down the tree from the current router and pass all found path parameters in path_params.