logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

binary_value.ex (608B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.EctoType.Config.BinaryValue do
  5. use Ecto.Type
  6. def type, do: :term
  7. def cast(value) when is_binary(value) do
  8. if String.valid?(value) do
  9. {:ok, value}
  10. else
  11. {:ok, :erlang.binary_to_term(value)}
  12. end
  13. end
  14. def cast(value), do: {:ok, value}
  15. def load(value) when is_binary(value) do
  16. {:ok, :erlang.binary_to_term(value)}
  17. end
  18. def dump(value) do
  19. {:ok, :erlang.term_to_binary(value)}
  20. end
  21. end