Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. defmodule App.Models.Settings do
  2. defstruct [
  3. newsletter: false,
  4. publish_profile: true,
  5. email_notifications: true
  6. ]
  7.  
  8. defmodule Type do
  9. @behaviour Ecto.Type
  10. alias App.Models.Settings
  11.  
  12. def type, do: :json
  13.  
  14. def cast(%Settings{} = settings), do: {:ok, settings}
  15. def cast(%{} = settings), do: {:ok, struct(Settings, settings)}
  16. def cast(_other), do: :error
  17.  
  18. def load(value), do: Poison.decode(value, as: App.Models.Settings)
  19.  
  20. def dump(value), do: Poison.encode(value)
  21. end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement