-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable support for using the shopify-money gem #213
base: main
Are you sure you want to change the base?
Conversation
Hey @jeremycw! Thanks for your contribution. That's really a tricky issue, those gems should ideally use different namespaces, it feels like But I understand that we can't expect that to happen, so in the meantime I'll recommend a slightly different approach. While your suggestion seems to work, it introduces a dependency on An alternative is introducing a configurable money adapter. It could be defined in I noticed that your PR mostly changes references to Let me know what you think. |
b04a8e4
to
a710673
Compare
Unfortunately `shopify-money` and `money` do not play well together. Both gems provide a `Money` class and an entry point into the gem at `lib/money.rb`. This makes it pretty difficult to include double_entry in a codebase that makes use of the `shopify-money` gem. To work around this I've added a configuration option `money_adapter` that allows double_entry to be configured to internally delegate methods to this adapter instead of using the `money` gem directly. This allows users of double_entry to provide an adapter class that allows integration with arbitrary money backends for better interoperability with their system. This was done by adding a `DoubleEntry::Money` class that delegates its singleton methods to the adapter.
@ricobl Thanks for the suggestion, that makes sense. I've taken a first pass at your suggestion. I've left |
This PR can be simplified by replacing |
@orien Could you take a look at this? It seems like the original reviewer is no longer a maintainer. |
@orien I want to see if there is any reason why we cannot get this merged and a new 2.1 release cut? |
@daande Are you using this branch in production already? Does it work as expected? |
Unfortunately
shopify-money
andmoney
do not play well together. Both gems provide aMoney
class and an entry point into the gem atlib/money.rb
. This makes it pretty difficult to include double_entry in a codebase that makes use of theshopify-money
gem.To work around this I've added a configuration option
shopify_money
that allows double_entry to be configured to internally use theshopify-money
gem instead of themoney
gem.shopify-money
was added as a development dependency since it's expected that people using this option will be requiringshopify-money
themselves. The specs can be run against either gem by providing theMONEY_GEM
env variable. For example:Omitting the
MONEY_GEM
var will use themoney
gem as usual.This was done by adding a
DoubleEntry::Money
class to abstract themoney
andshopify-money
apis. When usingmoney
it actually doesn't do anything and just returns the rawMoney
object. When usingshopify-money
it wraps the api to make it match the one provided by themoney
gem.Tested with
shopify-money
0.14.2 & 1.0.2.pre