Skogsrå v2.3.3 Skogsra.Type behaviour View Source

This module defines the functions and behaviours for casting Skogsra types.

Link to this section Summary

Functions

Uses Skogsra.Type for implementing the behaviour e.g. a naive implementation for casting "1, 2, 3, 4" to ["1", "2", "3", "4"] would be

Casts an environment variable.

Callbacks

Callback for casting a value.

Link to this section Functions

Uses Skogsra.Type for implementing the behaviour e.g. a naive implementation for casting "1, 2, 3, 4" to ["1", "2", "3", "4"] would be:

defmodule MyList do
  use Skogsra.Type

  def cast(value) when is_binary(value) do
    list =
      value
      |> String.split(~r/,/)
      |> Enum.map(&String.trim/1)
    {:ok, list}
  end

  def cast(_) do
    :error
  end
end

Specs

cast(Skogsra.Env.t(), term()) :: {:ok, term()} | :error

Casts an environment variable.

Link to this section Callbacks

Specs

cast(term()) :: {:ok, term()} | :error

Callback for casting a value.