defmodule Formatter do @moduledoc false def new_short_uid do UUID.uuid4() |> ShortUUID.encode!() end # def build_vcode() do # (:random.uniform() * 1000_000) |> round |> to_string # end def schema_to_map(s) do s |> Map.from_struct() |> Map.delete(:__meta__) end def clear_info(p, clear_list) when is_map(p) and is_list(clear_list) do Map.drop(p, clear_list) end def clear_info(p, _) do p end def get_image_names(object_uid, object_type) do case :rpc.call(Cluster.img_node(), Image, :image_path_of, [object_uid, object_type]) do # case :gen_rpc.call(Cluster.img_node(), Image, :image_path_of, [object_uid, object_type]) do :failed -> %{} img_paths when is_map(img_paths) -> img_paths {:badrpc, _} -> %{} end end end # For jason to encode some elixir types defimpl Jason.Encoder, for: [MapSet, Range, Stream] do def encode(struct, opts) do Jason.Encode.list(Enum.to_list(struct), opts) end end # Enumerable not implemented for Tuple, use Tuple.to_list defimpl Jason.Encoder, for: [Tuple] do def encode(struct, opts) do Jason.Encode.list(Tuple.to_list(struct), opts) end end