Enumex.Component behaviour (Enumex v1.0.0)

View Source

Provides a generic Domain Specific Language (DSL) for building enum components.

Bindings

A keyword list containing the variables that will be bound during component expansion. Bindings are different for both Enumex.Dynamic and Enumex.Static, but always includes a component key with a component module as a value, which is useful for writing behaviours.

Options

A keyword list that specifies component dependencies and requirements. A :depends option specifies the other components that this component relies on. The :requires option specifies a keyword list where the key is the app name and the value is a module, within the specified app, that this component relies on.

[
  depends: [OtherComponent],
  requires: [my_lib: MyLib.ModuleName]
]

Do block

A block containing the component implementation

defmodule MyApp.MyComponent do
  @moduledoc """
  A component documentation
  """

  use Enumex.Component

  @doc """
  A callback documentation
  """
  @callback my_func :: :ok

  comp [component: component_module] do
    @behaviour component_module

    @impl component_module
    def my_func, do: :ok
  end
end

Summary

Main

The type representing a data used in component bindings.

t()

The type representing a component module.

Main

comp(bindings \\ [], opts \\ [], list)

(macro)
@spec comp(
  Enumex.macro_input(%{:component => t(), optional(atom()) => Macro.t()}),
  Enumex.macro_input([option]),
  keyword(Macro.t())
) :: Macro.output()
when option: {:depends, [t()]} | {:requires, keyword(module())}

Defines a component.

Examples

defmodule DependentComponent do
  comp [key: value], depends: [OtherComponent], requires: [my_lib: MyLib.ModuleName] do
    # component contents …
  end
end

comp_binding_data()

@type comp_binding_data() :: [
  {:component, t()}
  | Enumex.Dynamic.comp_binding_data()
  | Enumex.Static.comp_binding_data()
]

The type representing a data used in component bindings.

t()

@type t() :: module()

The type representing a component module.