constructor v1.0.0-rc.0 Constructor behaviour

Documentation for Constructor.

Link to this section Summary

Callbacks

Implement this callback if you have some complex, multi-field validations that don't make sense in the constructor/2 macro. Or, if you prefer to eschew the constructor/2 macro entirely. Make a best-effort to rescue any errors and convert them to a {:error, any} tuple

Implement this callback if you have some complex, multi-field conversions that don't make sense in the constructor/2 macro. Or, if you prefer to eschew the constructor/2 macro entirely

Link to this section Types

Link to this type

conversion()
conversion() :: (field_item :: any() -> field_item :: any())

Link to this type

new_opts()
new_opts() :: [{:field_name, atom()}]

Link to this type

validation()
validation() ::
  (String.t() | atom(), any() -> :ok | {:error, {:constructor, map()}})

Link to this section Functions

Link to this macro

constructor(opts \\ [], list) (macro)

Link to this section Callbacks

Link to this callback

after_construct(struct)
after_construct(struct()) :: {:ok, any()} | {:error, {:constructor, map()}}

Implement this callback if you have some complex, multi-field validations that don't make sense in the constructor/2 macro. Or, if you prefer to eschew the constructor/2 macro entirely. Make a best-effort to rescue any errors and convert them to a {:error, any} tuple.

Link to this callback

before_construct(any)
before_construct(any()) :: {:ok, any()} | {:error, {:constructor, map()}}

Implement this callback if you have some complex, multi-field conversions that don't make sense in the constructor/2 macro. Or, if you prefer to eschew the constructor/2 macro entirely.

Link to this callback

new(input)
new(input :: map() | keyword() | [map()]) ::
  {:ok, struct() | [struct()] | nil} | {:error, {:constructor, map()}}

Link to this callback

new(input, opts)
new(input :: map() | keyword() | [map()], opts :: new_opts()) ::
  {:ok, struct() | [struct()] | nil} | {:error, {:constructor, map()}}

Link to this callback

new!(input)
new!(input :: map() | keyword() | [map()] | nil) ::
  struct() | nil | no_return()

Link to this callback

new!(input, opts)
new!(input :: map() | keyword() | [map() | nil], opts :: new_opts()) ::
  struct() | nil | no_return()