class Athena::Routing::RouteCollection
inherits Reference
#
Represents a collection of ART::Route
s.
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
Enumerable
Iterable
Methods#
#[](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.
#[]?(name : String) : ART::Route | Nil
#
Returns the ART::Action
with the provided name, or nil
if it does not exist.
#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.
#add(collection : self) : Nil
#
Adds all the routes from the provided collection to this collection.
#add_name_prefix(prefix : String) : Nil
#
Adds the provided prefix to the name of all routes stored within this collection.
#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.
#add_requirements(requirements : Hash(String, Regex | String)) : Nil
#
Merges the provided requirements into all routes stored within this collection.
#methods=(methods : String | Enumerable(String)) : Nil
#
Sets the method(s) of all routes stored within this collection.
#schemes=(schemes : String | Enumerable(String)) : Nil
#
Sets the scheme(s) of all routes stored within this collection.
#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.