dnsimple v0.9.0 Dnsimple.Utils
Summary
Functions
Converts the map into a struct
Functions
Specs
attrs_to_struct(Enum.t, module | map) :: map
Converts the map into a struct.
This function is similar to Kernel.struct/2, however it handles
the case where the struct fields are defined with atoms, and the map
instead is passed with keys as strings.
Moreover, compared to struct/2 the order of the parameter is swapped
so that it’s possible to use the |> operator pipelining the map.
Examples
defmodule User, do: defstruct [:id, :name]
{:module, User, _, %User{id: nil, name: nil}}
Dnsimple.Utils.attrs_to_struct(%{"name" => "weppos", "foo" => "bar"}, User)
%User{id: nil, name: "weppos"}