dnsimple v0.9.0 Dnsimple.Utils

Summary

Functions

attrs_to_struct(attrs, kind)

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"}
attrs_to_structs(collection, kind)

Specs

attrs_to_structs(List.t, module | map) :: map