Exmbus.Key (Exmbus v0.3.0)

View Source

This module provides a way to define and retrieve keys for the Exmbus parser.

Summary

Functions

Short-hand for getting the key struct out of the option key :key and calling key on that.

Given a Key struct, will invoke key function with options and context, and return a list of keys from the key function, or an error as appropriate.

Types

t()

@type t() :: %Exmbus.Key{
  keyfn: (Exmbus.Parser.Context.t() -> {:ok, [binary()]} | {:error, any()})
}

Functions

by_fn!(fun)

from_options(opts)

from_options!(opts)

get(ctx)

Short-hand for getting the key struct out of the option key :key and calling key on that.

See get/3

get(key, ctx)

@spec get(t(), ctx :: Exmbus.Parser.Context.t()) ::
  {:ok, [binary()]} | {:error, reason :: any()}

Given a Key struct, will invoke key function with options and context, and return a list of keys from the key function, or an error as appropriate.

iex> key = Key.by_fn!(fn(_ctx) -> {:ok, [<<1>>, <<2>>]} end) iex> {:ok, [<<1>>, <<2>>]} = Key.get(key, Exmbus.Parser.Context.new())