-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_string.ex
30 lines (27 loc) · 1.27 KB
/
to_string.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Kernel, except: [to_string: 1]
Code.compiler_options(ignore_module_conflict: true)
# Basic types
defimpl String.Chars, for: Tuple do
def to_string(value) do
case value do
{:ok, value} -> Point.Model.to_string(value)
value -> to_string value
end
end
end
defimpl String.Chars, for: Map do
alias Point.JSON
def to_string(value), do: JSON.to_pretty_json(value)
end
# Workaround to remoce a end zero in decimal number
defimpl String.Chars, for: Decimal do
def to_string(value), do: Decimal.to_string(Decimal.reduce(value), :normal)
end
# Domain types
defimpl String.Chars, for: Point.Currency, do: def to_string(model), do: Point.Model.to_string(model)
defimpl String.Chars, for: Point.Entity, do: def to_string(model), do: Point.Model.to_string(model)
defimpl String.Chars, for: Point.User, do: def to_string(model), do: Point.Model.to_string(model)
defimpl String.Chars, for: Point.Movement, do: def to_string(model), do: Point.Model.to_string(model)
defimpl String.Chars, for: Point.Account, do: def to_string(model), do: Point.Model.to_string(model)
defimpl String.Chars, for: Point.ExchangeRate, do: def to_string(model), do: Point.Model.to_string(model)
defimpl String.Chars, for: Point.Transaction, do: def to_string(model), do: Point.Model.to_string(model)