class Amber::Router::Parsers::OptionalSegmentResolver

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:

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

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(path : String) #

[View source]

Class Method Detail

def self.necessary?(path : String) : Bool #

[View source]
def self.resolve(path : String) : Array(String) #

[View source]

Instance Method Detail

def paths : Array(Array(String)) #

[View source]
def resolve #

Iterates the path array until there are no more optionals to resolve, populating the #paths array with resolutions.


[View source]
def resolve_optional(path : Array(String)) : Array(Array(String)) #

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.


[View source]