Skip to content
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

update to_money to have the same behaviour as Money.new #267

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

elfassy
Copy link
Contributor

@elfassy elfassy commented Jun 20, 2023

Why

To avoid gotchas, string.to_money("USD") should behave exactly the same as Money.new(string, "USD")
Also adding a deprecation warning to help us search the logs and identify incorrect uses for codebases with the legacy_deprecation option

# before
"1.234".to_money == Money.new("1234") # the . is assumed to be a european thousand separator
"1,234".to_money == Money.new("1234") # the , is assumed to be a NA thousand separator

# after
"1.234".to_money == Money.new("1.234") # the . is assumed to be a decimal delimiter
"1,234".to_money == Money.new("1,234") #=> raise exception 

What

Make the change but keep the old behaviour under the legacy_deprecations option... until we're confident we can remove it. For those with that legacy support, they can rely on the newly added rubocop rule to help them migrate away from the old .to_money

keep the old behaviour under the `legacy_deprecations` option
@elfassy
Copy link
Contributor Author

elfassy commented Jun 20, 2023

Comment on lines +17 to +22
if Money.config.legacy_deprecations
Money.deprecate("`#{self}.to_money` will raise an ArgumentError in the next major release")
Money::Parser::Fuzzy.parse(self, currency)
else
Money.new(self, currency)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the gem consumer will need to set legacy_deprecations to true for this to maintain the old behavior, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, correct, and that should only be used in core

@elfassy elfassy merged commit ad39232 into main Jun 27, 2023
@elfassy elfassy deleted the to_money_simple_parser branch June 27, 2023 14:06
@shopify-shipit shopify-shipit bot temporarily deployed to production August 9, 2023 17:39 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants