Kuddle.Config.Types (Kuddle Config v0.1.0) View Source

Annotation cast types.

User specific types can be registered by setting the kuddle_config types:

Example

config :kuddle_config,
  types: [
    typename: {Module, cast_function_name},

    geopoint: {MyGeoPoint, :cast},
  ]

The cast function must return {:ok, any()} or :error if it cannot cast the given value.

Kuddle Config has some default types they can be overwritten by setting the default_types:

config :kuddle_config,
  default_types: [
    date: {Date, :from_iso8601},
    utc_datetime: {Kuddle.Config.Types.DateTime, :cast},
    naive_datetime: {NaiveDateTime, :from_iso8601},
    time: {Time, :from_iso8601},
    decimal: {Kuddle.Config.Types.Decimal, :cast},
    atom: {Kuddle.Config.Types.Atom, :cast},
    boolean: {Kuddle.Config.Types.Boolean, :cast},
    tuple: {Kuddle.Config.Types.Tuple, :cast},
    list: {Kuddle.Config.Types.List, :cast},
  ]

The purpose of the default_types is to provide some sane default which doesn't require any additional configuration from you, the user.

However they can be disabled by setting the default_types config.

Link to this section Summary

Functions

Cast given value to a different type, normally the input will a string.

Link to this section Functions

Specs

cast(atom() | String.t(), any()) :: {:ok, any()} | :error

Cast given value to a different type, normally the input will a string.

Link to this function

internal_cast(type, value)

View Source

Specs

internal_cast(atom() | String.t(), any()) ::
  {:ok, any()} | {:error, term()} | :error