class LuckyRouter::Fragment(T)

Overview

A fragment represents possible combinations for a part of the path. The first/top fragment represents the first "part" of a path.

The fragment contains the possible static parts or a single dynamic part Each static part or dynamic part has another fragment, that represents the next set of fragments that could match. This is a bit confusing so let's dive into an example:

The Fragment would represent the possible combinations for the first part

# 'nil' because there is no route with a dynamic part in the first slot
fragment.dynamic_part # nil

# This returns a Hash whose keys are the possible values, and a value for the
*next* Fragment
fragment.static_parts

# Would return:
{"users" => Fragment, "posts" => Fragment}

# The Fragment in the 'users' key would have:

# DynamicFragment.new(:id, Fragment)
fragment.dynamic_part

# Static parts
fragment.static_parts
{"foo" => Fragment}

Gotcha

The last fragment of a path is "empty". It does not have static parts or dynamic parts

Defined in:

lucky_router/fragment.cr

Instance Method Summary

Instance Method Detail

def dynamic_part : DynamicFragment(T) | Nil #

[View source]
def dynamic_part=(dynamic_part : DynamicFragment(T) | Nil) #

[View source]
def find(parts : Array(String)) : Match(T) | NoMatch #

[View source]
def payload : T | Nil #

The payload is only set on the last fragment


[View source]
def payload=(payload : T | Nil) #

The payload is only set on the last fragment


[View source]
def process_parts(parts : Array(String), payload : T) #

[View source]
def static_parts #

[View source]