# `ExUtils.Configs`
[🔗](https://github.com/sheharyarn/ex_utils/blob/main/lib/ex_utils/configs.ex#L1)

Simplified helpers to work with Application configs in Elixir.

Before using this module, you must add the following to your
`config.exs` file:

```elixir
config :ex_utils, otp_app: :your_app
```

Replace `:your_app` with the actual OTP app atom.

# `from_priv!`

```elixir
@spec from_priv!(binary()) :: binary()
```

Build the absolute path of a file in the `priv/` directory,
given its relative path.

This is especially useful in compiled elixir releases.

## Examples

During development, the returned path might look like:

```elixir
iex> ExUtils.Configs.from_priv!("templates/email.html")
"priv/templates/email.html"
```

In a compiled release, it might look like:

```elixir
iex> ExUtils.Configs.from_priv!("templates/email.html")
"/opt/my_app/lib/my_app-1.0.0/priv/templates/email.html"
```

# `get`

```elixir
@spec get(atom(), atom() | list(), any()) :: any()
```

Gets a config value for the given access path.

Returns the given default when the value is `nil` or does not exist.

## Examples

Given `config :your_app, :features, uploads: [enabled: true]`:

```elixir
iex> ExUtils.Configs.get(:features, [:uploads, :enabled])
true
iex> ExUtils.Configs.get(:features, [:uploads, :max_size], :unlimited)
:unlimited
```

# `get!`

```elixir
@spec get!(atom()) :: any()
```

Reads the application configs of the OTP app.

Raises if the value is nil or does not exist.

## Example

Given the following application config:

```elixir
config :your_app, :mailer, adapter: MyApp.LocalAdapter
```

It can be retrieved with:

```elixir
iex> ExUtils.Configs.get!(:mailer)
[adapter: MyApp.LocalAdapter]
```

# `get!`

```elixir
@spec get!(atom(), atom() | list(), any()) :: any()
```

Same as `get/3` but raises when the value is `nil` or not found and no
default is provided.

# `read_from_priv!`

```elixir
@spec read_from_priv!(binary()) :: binary()
```

Read a file stored in the `priv/` directory.

Accepts a relative path of file inside `priv`.

## Example

Given a `priv/messages/welcome.txt` file containing `Welcome!`:

```elixir
iex> ExUtils.Configs.read_from_priv!("messages/welcome.txt")
"Welcome!"
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
