Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule App.Models.Settings do
- defstruct [
- newsletter: false,
- publish_profile: true,
- email_notifications: true
- ]
- defmodule Type do
- @behaviour Ecto.Type
- alias App.Models.Settings
- def type, do: :json
- def cast(%Settings{} = settings), do: {:ok, settings}
- def cast(%{} = settings), do: {:ok, struct(Settings, settings)}
- def cast(_other), do: :error
- def load(value), do: Poison.decode(value, as: App.Models.Settings)
- def dump(value), do: Poison.encode(value)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement