Mau.FilterRegistry (mau v0.8.0)

View Source

Dynamic filter registry that loads filters from module specs.

This registry automatically discovers filters by calling spec() functions on filter modules, providing better organization and discoverability.

Configuration

By default, uses compile-time module attributes for maximum performance. Enable runtime mode for user-defined filters:

config :mau, :enable_runtime_filters, true

Summary

Functions

Applies a filter to a value with the given arguments.

Returns a specification to start this module under a supervisor.

Gets a filter function by name.

Initializes the registry by loading all filters into state.

Starts the filter registry GenServer.

Types

filter_mfa()

@type filter_mfa() :: {module(), atom()}

filter_name()

@type filter_name() :: atom() | String.t()

Functions

apply(name, value, args \\ [])

@spec apply(filter_name(), any(), list()) ::
  {:ok, any()} | {:error, :filter_not_found | {:filter_error, any()}}

Applies a filter to a value with the given arguments.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(name)

@spec get(filter_name()) :: {:ok, filter_mfa()} | {:error, :not_found}

Gets a filter function by name.

Examples

iex> {:ok, {module, function}} = Mau.FilterRegistry.get(:upper_case)
iex> is_atom(module) and is_atom(function)
true

iex> Mau.FilterRegistry.get(:unknown_filter)
{:error, :not_found}

init(list)

Initializes the registry by loading all filters into state.

start_link(opts)

Starts the filter registry GenServer.