class

Athena::Routing::RouteCollection

Inherits Iterable < Enumerable < Reference < Object

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.

Instance 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.

Source
[]?(name : String) : ART::Route | Nil

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

Source
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.

Source
add(collection : self) : Nil

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

Source
add_defaults(defaults : Hash(String, _)) : Nil
Source
add_name_prefix(prefix : String) : Nil

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

Source
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.

Source
add_requirements(requirements : Hash(String, Regex | String)) : Nil

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

Source
clone

Returns a copy of self with all instance variables cloned.

Source
each

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

Source
each

Returns an Iterator for each registered route.

Source
methods=(methods : String | Enumerable(String)) : Nil

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

Source
remove(name : String) : Nil

Removes the route with the provide name.

Source
remove(*names : String) : Nil

Removes the routes with the provide names.

Source
routes

Returns the routes stored within this collection.

Source
schemes=(schemes : String | Enumerable(String)) : Nil

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

Source
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.

Source
size

Returns the number of routes stored within this collection.

Source