# `Delegator`
[🔗](https://codeberg.org/pfac/delegator)

Delegates functions and macros from one module to another.

Delegator extends Elixir's built-in delegation mechanism by providing powerful
macros for delegating multiple functions and macros at once, with fine-grained
control over which items are delegated and how they are named.

## Shared options

- `:as` - Rename delegated definitions. See `Delegator.AliasesMap.new/1`.
- `:except` - Exclude specific defintions. See `Delegator.AritiesMap.new/1`.
- `:only` - Include only specific defintions. See `Delegator.AritiesMap.new/1`.
- `:prefix` - Add prefix to delegated names. May be an atom or a string.
- `:suffix` - Add suffix to delegated names. May be an atom or a string.
- `:to` - Required. Which module to delegate to.

Passing `nil` to any option causes it to be ignored.

## Overrides

Functions delegated with `defdelegateall` are automatically marked as
overridable, allowing you to override them in your module.

Macros are never overridable.

# `defdelegateall`
*macro* 

Defines delegating functions for all functions in a module.

See the ["Shared options"](#module-shared-options) section at the module
documentation for more options.

# `defdelegateallmacros`
*macro* 

Defines delegating macros for all macros in a module.

See the ["Shared options"](#module-shared-options) section at the module
documentation for more options.

# `defdelegateeverything`
*macro* 

Define delegating functions and macros for everything in a module.

See the ["Shared options"](#module-shared-options) section at the module
documentation for more options.

# `defdelegatemacro`
*macro* 

Defines a macro that delegates to another module.

Similar to `defdelegate/2` but for macros.

## Options

* `:to` - the module to dispatch to. Required.
* `:as` - the macro to call on the target given in `:to`. Optional. Defaults
  to the name of the macro being delegated.

# `delegate_name`

Build a delegation name.

Takes the original definition as a name-arity tuple. It then looks for any
aliases matching that definition. If no alias is found, applies a prefix
and/or suffix when provided.

Prefix and suffix are not applied when an alias is provided, so the alias is
honored as provided.

When the definition name ends with `!` or `?`, the suffix is applied right
before these characters.

When the definition starts with `_`, no separator is placed after the prefix.
When it ends with `_`, no separator is placed before the suffix.

## Examples

    iex> Delegator.delegate_name({:foo, 1}, Delegator.AliasesMap.new(bar: :foo), :pre, :post)
    "bar"

    iex> Delegator.delegate_name({:foo, 1}, Delegator.AliasesMap.new(%{{:bar, 1} => :foo}), :pre, :post)
    "bar"

    iex> Delegator.delegate_name({:foo, 1}, Delegator.AliasesMap.new(), :pre, :post)
    "pre_foo_post"

    iex> Delegator.delegate_name({:foo!, 1}, Delegator.AliasesMap.new(), :pre, :post)
    "pre_foo_post!"

    iex> Delegator.delegate_name({:__foo__, 1}, Delegator.AliasesMap.new(), :pre, :post)
    "pre__foo__post"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
