thrash v0.3.0 Thrash.Enumerated
Builds an enumerated value module from thrift-generated erlang code.
Suppose you have thrift file with enumerated values:
// in thrift file
enum StatusCodes {
OK = 0
ERROR = 1
}
Bring these enumerated values into your Elixir app by doing
defmodule MyApp.StatusCodes do
use Thrash.Enumerated
end
As long as the name of your module ends with ‘StatusCodes’, Thrash
should find the enumerated values automatically. You can manually
override the name of the source enum by passing it to the use
call:
defmodule MyApp.Codes do
use Thrash.Enumerated, source: StatusCodes
end
The generated code defines a mapping from the named values, as atoms, to their corresponding integers:
StatusCode.id(:ok) = 0
StatusCode.atom(0) = :ok
Using this module defines the following functions:
map/0
- Returns the map from atom to valuereverse_map/0
- Returns the map from value to atomatoms/0
- Returns the list of valid atom valuesvalues/0
- Returns the list of valid integer valuesid/1
- Returns the integer value for a given atomatom/1
- Returns the atom value for a given integer
The following types are defined:
atom_t/0
- Union of all valid atom valuesvalue_t/0
- Union of all valid integer values