class Athena::Routing::RouteCollection

Overview

Represents a collection of ART::Routes. Provides a way to traverse, edit, remove, and access the stored routes.

Each route has an associated name that should be unique. Adding another route with the same name will override the previous one.

Route Priority

When determining which route should match, the first matching route will win. For example, if two routes were added with variable parameters in the same location, the first one that was added would match regardless of what their requirements are. In most cases this will not be a problem, but in some cases you may need to ensure a particular route is checked first.

The priority argument within #add can be used to control this order.

Included Modules

Defined in:

route_collection.cr

Instance Method Summary

Instance Method Detail

def [](name : String) : ART::Route #

Returns the ART::Action with the provided name.

Raises a ART::Exception::RouteNotFound if a route with the provided name does not exist.


[View source]
def []?(name : String) : ART::Route | Nil #

Returns the ART::Action with the provided name, or nil if it does not exist.


[View source]
def add(name : String, route : ART::Route, priority : Int32 = 0) : Nil #

Adds the provided route with the provided name to this collection, optionally with the provided priority.


[View source]
def add(collection : self) : Nil #

Adds all the routes from the provided collection to this collection.


[View source]
def add_defaults(defaults : Hash(String, _)) : Nil #

[View source]
def add_name_prefix(prefix : String) : Nil #

Adds the provided prefix to the name of all routes stored within this collection.


[View source]
def add_prefix(prefix : String, defaults : Hash(String, _) = Hash(String, String | ::Nil).new, requirements : Hash(String, String | Regex) = Hash(String, String | Regex).new) : Nil #

Adds a path prefix to all routes stored in this collection. Optionally allows merging in additional defaults or requirements.


[View source]
def add_requirements(requirements : Hash(String, Regex | String)) : Nil #

Merges the provided requirements into all routes stored within this collection.


[View source]
def clone #

Returns a copy of self with all instance variables cloned.


[View source]
def each(&) : Nil #

Yields the name and ART::Route object for each registered route.


[View source]
def each #

Returns an Iterator for each registered route.


[View source]
def methods=(methods : String | Enumerable(String)) : Nil #

Sets the method(s) of all routes stored within this collection.


[View source]
def remove(name : String) : Nil #

Removes the route with the provide name.


[View source]
def remove(*names : String) : Nil #

Removes the routes with the provide names.


[View source]
def routes : Hash(String, ART::Route) #

Returns the routes stored within this collection.


[View source]
def schemes=(schemes : String | Enumerable(String)) : Nil #

Sets the scheme(s) of all routes stored within this collection.


[View source]
def set_host(host : String, defaults : Hash(String, _) = Hash(String, String | ::Nil).new, requirements : Hash(String, String | Regex) = Hash(String, String | Regex).new) : Nil #

Sets the host property of all routes stored in this collection. Optionally allows merging in additional defaults or requirements.


[View source]
def size : Int #

Returns the number of routes stored within this collection.


[View source]