Lamina.DSL.Config (lamina v0.4.2)

Defines the macros used inside the config macro.

Summary

Functions

Specify a transformation function to cast the value to the final required type.

Specify a validation function to ensure that the value is valid.

Functions

Link to this macro

cast(cast_fn)

(macro)
@spec cast((any() -> any())) :: Macro.t()

Specify a transformation function to cast the value to the final required type.

Some configuration providers (most notably Env) are only able to return strings, so it can be necessary to modify them before they're returned to the user.

Example

defmodule MyHttpServer.Config do
  use Lamina

  provider(Lamina.Provider.Env)

  config :listen_port do
    cast(&String.to_integer/1)
  end
end
Link to this macro

validate(validate_fn)

(macro)
@spec validate((any() -> boolean())) :: Macro.t()

Specify a validation function to ensure that the value is valid.

Gives you an opportunity to ensure that the value about to be returned to the user is correct.

Example

defmodule MyFileReader.Config do
  use Lamina

  provider(Lamina.Provider.Env)

  config :file_to_read do
    validate(fn
      "/etc/password" -> false
      _ -> true
    end)
  end
end