Umbra Build StatusCoverage Status

Umbra is a GenServer utility helping you to easily create GenServer module. It helps to reduce boilerplate code by offering you macros and code generation.

Nothing obscure or magic, the code is really readable and comprehensive.

Installation

Add umbra for Elixir as a dependency in your mix.exs file.

def deps do
  [
    {:umbra, "~> 0.0.2"},
  ]
end

After you are done, run this in your shell to fetch the new dependency:

$ mix deps.get

Getting started

To get started, after adding the dependency to your mix project, you only have to use the Umbra.GenServer and the codes did starts to be generated.

Here is a really simple exemple:

defmodule BasicGenServer do
  use Umbra.GenServer

  definit do: {:ok, state}

  defcall {:get_state}, do: {:reply, state, state}

  defcast {:set_state, new_state}, do: {:noreply, new_state}

  defcast {:increment}, do: {:noreply, state + 1}

  defcast {:decrement}, do: {:noreply, state - 1}
end

{:ok, pid} = BasicGenServer.start_link(0) # state = 0
:ok = BasicGenServer.increment(pid) # state = 1
:ok = BasicGenServer.increment(pid) # state = 2
:ok = BasicGenServer.decrement(pid) # state = 1
:ok = BasicGenServer.set_state(pid, 42) # state = 42
{:ok, 42} = BasicGenServer.get_state(pid)

To deep further, please take a look at HexDocs.

Tests

The project is tested for:

Elixir versionOTP version
1.7.419.4
1.7.420.3
1.7.421.3
1.7.422.3
1.8.220.3
1.8.221.3
1.8.222.3
1.9.420.3
1.9.421.3
1.9.422.3
1.10.321.3
1.10.322.3
1.10.323.0

Contributing

Contributions are welcome!

  • Fork it!
  • Create your feature branch (git checkout -b your-new-feature).
  • Commit your change in only one commit (git commit -am "Add my new feature").
  • Push your change on your fork (git push origin your-new-feature).
  • Create a new Pull Request.

Author

Sylvain Corsini (@scorsi)

Credits

The project took inspiration from the well-known ExActor.