Closed oyeb closed 6 years ago
I've hit a wall with writing integration tests for the money libs. The problem is that all these libs have a "naked" Money
module/type, so if I add them to our deps()
, the module gets redefined, as expected!
Moreover, there's no way for me to refer to the Money
type from ex_money
differently from the Money
type from money
(note that there's always only 1 Money
type at the end (of compilation)).
Because the module is naked, I can't implement the protocol for them in Gringotts. But we can send a PR to their projects, where they can implement our protocol. They won't have to add our lib as a dependency. It'll look something like:
# Add this in their money.ex
if Code.ensure_compiled?(Gringotts.Money) do
defimpl value(money) do
...
end
defimpl currency(money) do
...
end
end
If we ever change our protocol, we send PRs. If they make a breaking change later, it's their responsibility to mend it.
Building on the discussion in #62, this PR introduces a protocol to replace
amount
argument, and removes the need to specifycurrency
in config oropts
. There's a fallback implementation forAny
which enables us to supportex_money
andmonetized
right out of the box.Todo
Please push commits to resolve the following:
amount
tovalue
... as anamount
can be seen to have avalue
in a specificcurrency
.ex_money
as dependency and implement the protocol for it.