Enumex.Static.Components.Constant (Enumex v1.0.0)

View Source

A component that generates constant functions for each enum value.

Constant functions

Functions with the following naming would be generated:

  • const_#{enum_name}_#{id} - returns the Enumex.Value struct
  • const_#{enum_name}_#{index} - returns the Enumex.Value struct
  • const_id_#{enum_name}_#{index} - returns id of the enum value
  • const_index_#{enum_name}_#{id} - returns index of the enum value

Example

defmodule MyApp.Enums do
  use Enumex.Static, components: [Enumex.Static.Components.Constant]

  # enum definitions go here
end

iex> MyApp.Enums.const_my_enum_1()
Enumex.Value.new(MyApp.Enums, :my_enum, :first, 1)
iex> MyApp.Enums.const_my_enum_first()
Enumex.Value.new(MyApp.Enums, :my_enum, :first, 1)
iex> MyApp.Enums.const_my_enum_id_1()
:first
iex> MyApp.Enums.const_my_enum_index_first()
1