class Athena::Routing::RouteCollection
- Athena::Routing::RouteCollection
- Reference
- Object
Overview
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({String, Athena::Routing::Route})
- Iterable({String, Athena::Routing::Route})
Defined in:
route_collection.crInstance Method Summary
-
#[](name : String) : ART::Route
Returns the
ART::Action
with the provided name. -
#[]?(name : String) : ART::Route | Nil
Returns the
ART::Action
with the provided name, ornil
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_defaults(defaults : Hash(String, _)) : Nil
-
#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.
-
#add_requirements(requirements : Hash(String, Regex | String)) : Nil
Merges the provided requirements into all routes stored within this collection.
-
#clone
Returns a copy of
self
with all instance variables cloned. -
#each(&) : Nil
Yields the name and
ART::Route
object for each registered route. -
#each
Returns an
Iterator
for each registered route. -
#methods=(methods : String | Enumerable(String)) : Nil
Sets the method(s) of all routes stored within this collection.
-
#remove(name : String) : Nil
Removes the route with the provide name.
-
#remove(*names : String) : Nil
Removes the routes with the provide names.
-
#routes : Hash(String, ART::Route)
Returns the 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.
-
#size : Int
Returns the number of routes stored within this collection.
Instance Method Detail
Returns the ART::Action
with the provided name.
Raises a ART::Exception::RouteNotFound
if a route with the provided name does not exist.
Returns the ART::Action
with the provided name, or nil
if it does not exist.
Adds the provided route with the provided name to this collection, optionally with the provided priority.
Adds all the routes from the provided collection to this collection.
Adds the provided prefix to the name of all routes stored within this collection.
Adds a path prefix to all routes stored in this collection. Optionally allows merging in additional defaults or requirements.
Merges the provided requirements into all routes stored within this collection.
Sets the method(s) of all routes stored within this collection.
Sets the scheme(s) of all routes stored within this collection.
Sets the host property of all routes stored in this collection. Optionally allows merging in additional defaults or requirements.