Exmbus.Key (Exmbus v0.3.0)
View SourceThis 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
@type t() :: %Exmbus.Key{ keyfn: (Exmbus.Parser.Context.t() -> {:ok, [binary()]} | {:error, any()}) }
Functions
Short-hand for getting the key struct out of the option key :key and calling key on that.
See get/3
@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())