-
Notifications
You must be signed in to change notification settings - Fork 620
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
[PATCH] Represent currencies as Currency object #4
Comments
Thanks for the patch. I'll take a look at it and see about incorporating it into trunk. |
I have no problem merging this if you make one change. The Brazilian Real should always have a space between the symbol and the amount. You can see we had to patch this with the following commit 898d462. Once that is updated, I will merge your changes into trunk. |
Great! I updated the repository. Make sure to destroy/recreate the remote source if you already fetched it because I used a rebase strategy to clean the commit history. Thanks for your quick feedback! |
I've merged your changes into trunk. I've sent a message to Hong Lai, and as long as he doesn't object, I will release a new version of the gem. |
Excellent! I wish that all projects have this reactivity. Thank you! -- Simone |
Looks good, excellent work! Thanks for contributing. The only thing that I don't understand is the priority thing in Currency. It'd be great if you can document that in more detail. Other than that, feel free to release. |
No problem. I added a few more documentation in the following 2 changesets in my fork. The changes should apply cleanly in your fork queue. If not, let me know, I'll rebase them on your repos. |
The updated gem has been released! |
I think patch broke the composed_of example for using the money gem with rails. In my model I have:
Saving a variant object works, but when I load it back from the database, I get a YAML string instead:
I have found two solutions to this, the first is to add |
In my Rails app I extended the Money class with two additional methods
And here's my model definition
|
can you submit a patch to the documentation with you methods? |
I have a doubt about the usefulness of my patch. The two methods above are strictly focused on ActiveRecord composite feature. Whilst the first might be partially useful for the Money library itself, the second one is technically wrong. In fact, it allows you to change the internal value for What do you think? |
I'm having a hard time deciding what to do here. I don't want to put ActiveRecord specific code into the library, and I don't see the use of I'm not very familiar with ActiveRecord, but is there anyway to use the |
The :converter option is only used when the assigned object is of another class than specified (Money in this case). It can be used to make variant.price = 100 be converted to Money.new(10000, 'SEK') for example, but if I send a Money object the converter is not run. In my example above I have cents and currency in separate columns, what happens is that AR runs something like write_attribute(:currency, money_object.send(:currency)). In 2.2, currency would have been a string, which gets saved properly, but since it's an object in 2.3, AR magically serializes it to YAML before saving it. |
You use
ActiveRecord expects the values in the mapping hash to be compatible. If you set
It won't work because it tries to serialize the currency object instead of calling the I agree, I wouldn't change the Money Gem to fit an ActiveRecord use case. This is exactly the reason why I haven't included the patch before. |
Go ahead and write up the documentation and I'll merge it into trunk and release it. |
http://github.com/weppos/money/compare/3d48d49a94950dcb297d...0dd2f8e78032d0054ee1 I also committed 3 other changes. Feel free to review and merge them if you agree with the changes. |
Looks good. I see a typo though: Should be "Alternatively you can use the convenience methods like" I'm not so happy with the ActiveRecord breakage. API breakages should result in a major version bump (e.g. 3.0.0) but the issue has been discovered after the release so no use in crying over spilled milk. The ActiveRecord instructions should definitely be updated. You've written a new "Money 2.3 and ActiveRecord" section, but why isn't it part of the "Ruby on Rails" section? The "Ruby on Rails" section still contains incorrect code. |
I was thinking perhaps we should bump the major version once we get everything sorted out. |
@ FooBarWidget Fixed the typo, and reorganized the Rails section |
Yes agreed with the major version bump. @weppos: looks good. You should document that a breakage occurred in 2.3.0 though, and that previous versions used #currency and didn't need the patch. |
I just noticed that the Github link in README.rdoc doesn't work very well. It links to this issue but the browser doesn't scroll to the correct comment. Can you document the issue directly in the README so that readers don't have to wade through all of our comments in search for the right one? |
I merged weppos' changes into trunk and bumped the version. Take a look at the documentation and make sure we don't need anymore changes, then I'll release the gem. |
I also created two pages on the wiki to detail information about this issue. |
Looks good. |
The gem has been released and the documentation has been updated. |
|
In my money fork I added the ability to represent currencies with Money::Currency.
http://github.com/weppos/money
Additional changes:
All commits are submitted along with a corresponding test suite.
I hope you would merge my changes to the mainstream repository.
I worked hard to ensure backward-compatibility with existing API.
-- Simone
The text was updated successfully, but these errors were encountered: