Current section

Files

Jump to
retort lib retort case.ex
Raw

lib/retort/case.ex

defmodule Retort.Case do
@moduledoc """
Helps for creating factories over RPC and converting their format back
"""
@spec create_list!((map -> struct), map, non_neg_integer) :: [struct]
def create_list!(create!, context, size) when is_integer(size) do
# bare value for dogma
create_for_context! = fn -> create!.(context) end
create_for_context!
|> Stream.repeatedly
|> Enum.take(size)
end
@spec stringify_keys(map) :: %{optional(binary) => term}
def stringify_keys(map) when is_map(map) do
Enum.into map, %{}, fn
{key, value_struct = %{__struct__: _}} ->
{to_string(key), value_struct}
{key, nested_map} when is_map(nested_map) ->
{to_string(key), stringify_keys(nested_map)}
{key, value} ->
{to_string(key), value}
end
end
@spec unknown_relationship_path_document() :: Alembic.Document.t
def unknown_relationship_path_document do
%Alembic.Document{
errors: [
%Alembic.Error{
detail: "`unknown` is an unknown relationship path",
meta: %{
"relationship_path" => "unknown"
},
source: %Alembic.Source{
parameter: "include"
},
title: "Unknown relationship path"
}
]
}
end
end