Massex
Massex is a simple pattern for holding masses and interacting with them in a sensible manner. It follows the whole value pattern, and allows easy storage, retrieval and mathematics upon values of mass in disparate scales.
iex> one = Massex.new(10, :gram)
...> two = Massex.new(10, :ounce)
...> Massex.add(one, two)Supporting Libraries
Massex ships with Jason support which will automatically be loaded if your project is using Jason for JSON handling. Additionally, it also supports Absinthe and Ecto.
Absinthe
To activate the Absinthe support, just import the types in your schema:
import_types Massex.Absinthe.TypeYou can then use Massex objects in your Schemas
object :lorry do
field :mass, :mass
endOr in your mutations
payload field :set_lorry_mass do
input do
field :id, non_null(:id)
field :mass, non_null(:mass_input)
end
endEcto
You can transparently store Massex structs in your schemas by adding the mass field as a map/json/jsonb type in your schema.
schema "lorries" do
field :mass, Massex.Ecto.Type
endInstallation
If available in Hex, the package can be installed
by adding massex to your list of dependencies in mix.exs:
def deps do
[
{:massex, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/massex.