Skip to content

class Athena::Routing::RouteCollection
inherits Reference #

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

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.

View source

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

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

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

View source

#add(collection : self) : Nil#

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

View source

#add_defaults(defaults : Hash(String, _)) : Nil#

View source

#add_name_prefix(prefix : String) : Nil#

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

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

View source

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

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

View source

#clone#

Returns a copy of self with all instance variables cloned.

View source

#each : Nil#

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

View source

#each#

Returns an Iterator for each registered route.

View source

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

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

View source

#remove(name : String) : Nil#

Removes the route with the provide name.

View source

#remove(*names : String) : Nil#

Removes the routes with the provide names.

View source

#routes : Hash(String, ART::Route)#

Returns the routes stored within this collection.

View source

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

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

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

View source

#size : Int#

Returns the number of routes stored within this collection.

View source