Dry (dry v0.1.9)

Allow for creating structs, with fields of certain type, default value, custom function and more.

Example:

defmodule Sibling do
  use Dry
  alias Dry.Types

  schema do
    attribute(:name, Types.String)
  end
end

defmodule User do
  use Dry
  alias Dry.Types

  schema do
      attribute(:name, Types.String)
      attribute(:age, Types.Integer.options(optional: true))
      attribute(:height)
      attribute(:country, Types.String.options(default: "UK"))
      attribute(:siblings, Types.Array.options(type: Sibling))
      attribute(:favourite_colours, Types.Array.options(type: Types.String, default: ["blue", "green"]))

      attribute :is_adult do
        Map.get(entity, :age, 0) >= 18
      end

      attribute :tall do
        Map.get(entity, :height, 0) >= 180
      end
  end
end

user = User.new!(%{name: "Rob", age: 18, height: 169, country: "BG", siblings: [%{name: "John"}]})
user == %User{
  age: 18,
  country: "BG",
  height: 169,
  is_adult: true,
  name: "Rob",
  tall: false,
  siblings: [%Sibling{name: "John"}],
  favourite_colours: ["blue", "green"]
}
{:ok, _user} = User.new(%{name: "Rob", age: 18, height: 169, country: "BG", siblings: [%{name: "John"}]})  ```

Link to this section Summary

Link to this section Functions

Link to this macro

attribute(name)

(macro)
Link to this macro

attribute(name, type)

(macro)
Link to this macro

attribute(name, type, opts)

(macro)

Macro to define attribute withing a Dry schema Examples:

attribute(:age, :integer, optional: true)

Valid types can be - :atom, :string, :integer, :float, :bool, :map, :atom or a struct

Link to this macro

attribute?(name)

(macro)
Link to this macro

attribute?(name, type)

(macro)
Link to this function

map_to(value, struct)

Link to this macro

schema(list)

(macro)