Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Elixir app example

An Elixir application split into three packages. It builds and tests on the pinned Elixir and Erlang/OTP runtimes with nothing installed on the host.

PackageRole
catalogcatalog library: item parsing, a unit table generated from units.txt, and JSON through jason
stockstock application: a supervised GenServer ledger with a per-item limit from app_env
clistockctl escript that runs commands against the ledger
bazel build //examples/elixir-app/...
bazel test //examples/elixir-app/...
bazel run //examples/elixir-app/cli:stockctl -- "add 2 dozen pears" "count pears"

The run prints 24, 24 and the snapshot [{"name":"pears","units":24}]. A command that fails prints error: ... and exits 1.

catalog:catalog_test covers parsing, the generated table and the JSON output. stock:ledger_test covers the limit from app_env, the application graph, and supervisor restarts after a kill and after a crash. cli:stockctl_test runs the commands in process and through the stockctl launcher.

jason is a pinned hex_package declared in MODULE.bazel.