class Amber::Router::Parsers::OptionalSegmentResolver
- Amber::Router::Parsers::OptionalSegmentResolver
- Reference
- Object
Overview
Resolves "optional" segments in urls to many urls.
In this class an optional is a parenthetical statement. For example, these urls all have one or more optional segments:
users/:id(.format)
relatives(/:id/children)
students(/peers(/teachers))
This resolver pays no attention to url structure other than parenthesis. As a result, care should be taken to properly structure optionals so that resolved urls are valid. It is easiest to maintain valid resolved urls by consistently placing delimiters relative to optional boundaries. For example:
All optionals begin with a delimiter: users/:id(/children(/grandchildren))/
All optionals end with a delimiter: users/:id/(children/(grandchildren/))
Both examples produce the same result, which is this set of paths:
[
"users/:id/",
"users/:id/children/",
"users/:id/children/grandchildren/",
]
However, it is unwise to mix styles because it results in incorrect url delimiters.
For example: users/:id(/children/(grandchildren/))/cousins
Produces this set of paths:
[ "users/:id/cousins", "users/:id/children//cousins", "users/:id/children/grandchildren//cousins", ]
Defined in:
amber_router/parsers/optionals.crConstructors
Class Method Summary
Instance Method Summary
- #paths : Array(Array(String))
-
#resolve
Iterates the path array until there are no more optionals to resolve, populating the
#paths
array with resolutions. -
#resolve_optional(path : Array(String)) : Array(Array(String))
Converts a single path with at least one optional into two paths.
Constructor Detail
Class Method Detail
Instance Method Detail
Iterates the path array until there are no more optionals to resolve,
populating the #paths
array with resolutions.
Converts a single path with at least one optional into two paths. One with the optional and one without.
When a path has nested optionals, only the outermost optional is resolved.