ExGram.Router.Scope (ex_gram_router v0.1.0)

Copy Markdown View Source

Internal data structure representing a node in the routing tree.

A scope is either:

  • A leaf: has a handler (and optionally filters), no children.
  • A branch: has filters and children scopes, no handler.

Scopes are built at compile time by the DSL macros and stored as a nested structure. At runtime, the dispatcher walks this tree top-to-bottom to find the first matching handler.

Summary

Functions

Returns true if the scope is a leaf node (has a handler and no children).

Types

filter()

@type filter() :: {module(), term()}

handler()

@type handler() ::
  {module(), atom(), 1 | 2}
  | (ExGram.Cnt.t() -> ExGram.Cnt.t())
  | (term(), ExGram.Cnt.t() -> ExGram.Cnt.t())

t()

@type t() :: %ExGram.Router.Scope{
  children: [t()],
  filters: [filter()],
  handler: handler() | nil
}

Functions

leaf?(scope)

Returns true if the scope is a leaf node (has a handler and no children).