Helper.Enum (helper v1.0.1) View Source
This module is use
d to create an Enum like so:
use Helper.Enum, :name, :ready, :set, :go
It is heavily inspired (copied) from Ecto.Enum, but pruned to meet our needs, which did not include Ecto integration
The option is a keyword list of name/value pairs
The name argument takes an atom or a tuple with the singular and plural values as atoms.
For values argument, it accepts a list of atoms
Below are examples of a valid argument:
use Helper.Enum, name: :status, values: [:registered, :active, :inactive, :archived]
use Helper.Enum, name: [:state, :states], values: [registered: 0, active: 1, inactive: 2, archived: 3]
This helper provides functions for inspecting the enum at runtime.
__valid_states__/0
- returns the valid values
valid_state?/1
- returns boolean to indicate valid value
Enum also generates a typespec for use with dialyzer, available as state()
type
Link to this section Summary
Functions
Define the enum.
Link to this section Functions
Specs
__using__(keyword()) :: Macro.output()
Define the enum.