Current section
Files
Jump to
Current section
Files
lib/helper.ex
defmodule Helper do
@moduledoc """
Documentation for `Helper`.
"""
@type ast() :: Macro.t()
@doc false
@spec m_raise(binary()) :: ast()
defmacro m_raise(m), do: quote(do: raise(CompileError, description: unquote(m)))
@spec merge(t1, t2) :: t1 when t1: map() | keyword(), t2: t1
def merge(e1, e2) when (is_list(e1) and is_list(e2)) or (is_map(e1) and is_map(e2)),
do: DeepMerge.deep_merge(e1, e2)
@doc false
@spec ast2mod!(atom | ast() | list()) :: module() | no_return()
def ast2mod!([m]), do: ast2mod!(m)
def ast2mod!(m) when is_atom(m), do: m
def ast2mod!({:__aliases__, _, m}) when is_list(m), do: Module.concat(m)
def ast2mod!(e), do: m_raise("#{inspect(e)}: Invalid value for module")
@doc false
@spec to_atom!(binary()) :: atom() | no_return()
def to_atom!(b) when is_binary(b) do
String.to_existing_atom(b)
rescue
ArgumentError -> String.to_atom(b)
end
@doc false
def to_atom!(a) when is_atom(a), do: a
def to_atom!(e), do: raise(ArgumentError, "#{inspect(e)}: Invalid value. Expected binary")
end