Skip to content

Commit 32b9b3b

Browse files
committed
Delete Ecto deps from generating UUID
1 parent 195afac commit 32b9b3b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Changelog for MishkaDeveloperTools 0.1.6
2+
3+
### Features:
4+
5+
- [x] Add `Crypto` helper module
6+
- [x] Add new optional dependencies and their wrappers [`nimble_totp`, `joken`, `jason`, `plug`, `bcrypt_elixir`, `pbkdf2_elixir`, `argon2_elixir`]
7+
18
# Changelog for MishkaDeveloperTools 0.1.5
29

310
---

lib/helper/uuid.ex

+32-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,37 @@ defmodule MishkaDeveloperTools.Helper.UUID do
1313
@type t :: <<_::288>>
1414
@type raw :: <<_::128>>
1515

16+
defmodule HelperEcto.CastError do
17+
@moduledoc """
18+
Raised when a changeset can't cast a value.
19+
"""
20+
defexception [:message, :type, :value]
21+
22+
def exception(opts) do
23+
type = Keyword.fetch!(opts, :type)
24+
value = Keyword.fetch!(opts, :value)
25+
msg = opts[:message] || "cannot cast #{inspect(value)} to #{format(type)}"
26+
%__MODULE__{message: msg, type: type, value: value}
27+
end
28+
29+
@doc """
30+
Format type for error messaging and logs.
31+
"""
32+
def format({composite, type}) when composite in [:array, :map] do
33+
"{#{inspect(composite)}, #{format(type)}}"
34+
end
35+
36+
def format({:parameterized, type, params}) do
37+
if function_exported?(type, :format, 1) do
38+
apply(type, :format, [params])
39+
else
40+
"##{inspect(type)}<#{inspect(params)}>"
41+
end
42+
end
43+
44+
def format(type), do: inspect(type)
45+
end
46+
1647
@spec cast(t | raw | any) :: {:ok, t} | :error
1748
def cast(uuid)
1849

@@ -36,7 +67,7 @@ defmodule MishkaDeveloperTools.Helper.UUID do
3667
def cast!(uuid) do
3768
case cast(uuid) do
3869
{:ok, hex_uuid} -> hex_uuid
39-
:error -> raise Ecto.CastError, type: __MODULE__, value: uuid
70+
:error -> raise HelperEcto.CastError, type: __MODULE__, value: uuid
4071
end
4172
end
4273

0 commit comments

Comments
 (0)