Contexted.Delegator (contexted v0.3.2)
The Contexted.Delegator
module provides a macro to delegate all functions defined within a specific module.
This module can be used to forward all function calls from one module to another without the need to write
individual defdelegate
statements for each function.
usage
Usage
To use the delegate_all
macro, simply include it in your module and pass the target module as an argument:
defmodule MyContextModule do
import Contexted.Delegator
delegate_all MyTargetSubcontextModule
end
All public functions defined in MyTargetSubcontextModule
will now be accessible within MyContextModule
.
Note: This macro should be used with caution, as it may lead to unexpected behaviors if two modules with overlapping function names are delegated.
additional-configuration
Additional configuration
The Contexted.Delegator
module can be used without Mix.Tasks.Compile.Contexted
as one of the compilers.
However, if you wish to enable automatic @doc
and @spec
generation for delegated functions, you will need to set the following config:
config :contexted,
enable_recompilation: true
Link to this section Summary
Functions
Delegates all public functions of the given module.
Link to this section Functions
Delegates all public functions of the given module.
examples
Examples
defmodule MyContextModule do
import Contexted.Delegator
delegate_all MyTargetSubcontextModule
end
All public functions defined in MyTargetSubcontextModule
will now be accessible within MyContextModule
.