View Source Behaves (Behaves v0.1.0)

Behaves allows you to check if an Elixir module implements a given behaviour.

Summary

Functions

Returns the list of behaviours implemented by impl.

Returns :ok if the impl implements the behaviour.

Returns :ok if a given impl implements the behaviour or raises.

Returns true if impl implements the behaviour or false if it does not.

Functions

@spec like_a(impl :: atom()) :: [module()]

Returns the list of behaviours implemented by impl.

Behaviours are sorted in the same order of @behaviours defined in the impl module.

@spec like_a(impl :: atom(), behaviour :: atom()) ::
  :ok
  | {:not_implemented, {module(), module()}}
  | {:not_a_behaviour, module()}
  | {:not_a_module, atom()}

Returns :ok if the impl implements the behaviour.

In other cases, returns:

  • {:not_implemented, {impl, behaviour}} if the implementation dos not implements the behaviour
  • {:not_a_module, impl} if impl is not a module
  • {:not_a_module, behaviour} if behaviour is not a module
  • {:not_a_behaviour, behaviour} if behaviour is not a behaviour
Link to this function

like_a!(impl, behaviour)

View Source
@spec like_a!(impl :: atom(), behaviour :: atom()) :: :ok

Returns :ok if a given impl implements the behaviour or raises.

Possible raised errors are:

Link to this function

like_a?(impl, behaviour)

View Source
@spec like_a?(impl :: atom(), behaviour :: atom()) :: boolean()

Returns true if impl implements the behaviour or false if it does not.