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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Money library change #110

Merged
merged 2 commits into from Oct 18, 2021
Merged

Money library change #110

merged 2 commits into from Oct 18, 2021

Conversation

agrberg
Copy link
Collaborator

@agrberg agrberg commented Oct 17, 2021

While working with the money_helper library to enable the upgrade in #109 I realized my non-breaking change in artsy/money_helper#27 would eventually need to be a breaking change to improve the API. with_symbol is just a pass through to symbol for the Money#format options and that PR enables those to be passed through directly.

When I looked at the money library itself, I determined Resource.to_dollar could instead depend on an even smaller interface as the defaults make sense for the purposes of a US market API.

A minor drawback/benefit is that this effectively drops the hidden dependency on activesupport (for built gems, it is still needed in test for danger-toc).

Feedback very welcome 馃檹

Copy link
Owner

@dblock dblock left a comment

Choose a reason for hiding this comment

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

I definitely prefer this to continuing to rely on money_helper.

For ActiveSupport, ++.

require 'money'

Money.locale_backend = :currency
Money.default_currency = 'USD'
Copy link
Owner

Choose a reason for hiding this comment

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

This global worries me because it will impact anyone using this gem and money directly. Default these in parameters as needed, but don't change any global defaults.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. I didn't know how big of a deal it would be as the locale_backend is set in money_helper https://github.com/artsy/money_helper/blob/main/lib/money_helper.rb#L9 but happy to make the change.

Copy link
Owner

Choose a reason for hiding this comment

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

So does this mean that we can accidentally break someone? Is this set anywhere in our tests?

I think this deserves an entry in UPGRADING.md with something like "you may need to set these in your application"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If they use Money in their project w/o setting locale_backend it will generate the following deprecation warning:

[DEPRECATION] You are using the default localization behaviour that will change in the next major release. Find out more - https://github.com/RubyMoney/money#deprecation

Depending where it is used, it can generate the following error:

I18n::InvalidLocale (:en is not a valid locale)

For example, I get this error when calling Money#format without the thousands_separator or decimal_mark options in the console for this project. However, I have no problem in the Rails project I'm using this gem in.

Definitely worth putting something in UPGRADING.MD.

Copy link
Owner

@dblock dblock left a comment

Choose a reason for hiding this comment

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

I have a question and a nit.

@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.add_dependency 'faraday', '>= 0.17'
s.add_dependency 'faraday_middleware'
s.add_dependency 'hashie'
s.add_dependency 'money_helper'
s.add_dependency 'money', '~> 6.0'
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need to lock to 6.0 major? Most likely 7 will work fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We unfortunately do 馃槶 . 7 is still unreleased, introduces breaking changes, and even changes the name of the gem to money2 though the API is still on Money.

lib/iex-ruby-client.rb Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
raise ArgumentError unless options[:date].present?
raise ArgumentError unless options[:chartByDay].present?
raise ArgumentError unless options[:date]
raise ArgumentError unless options[:chartByDay]
Copy link
Owner

Choose a reason for hiding this comment

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

Those don't support nil values, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to the current API docs chartByDay is an optional query param so we shouldn't enforce it being set here.

I can update the code and test but it feels separate from the purpose of this PR.

Drop dependency on `money_helper`
  Utilize `money` directly as defaults are for USD
  Remove #present? as `money_helper` brought in active support
@dblock dblock merged commit 7588c5c into dblock:master Oct 18, 2021
@dblock
Copy link
Owner

dblock commented Oct 18, 2021

Merged. Maybe we should release as 1.6, feels too major for a patch version bump.

@agrberg agrberg deleted the money_lib_change branch October 18, 2021 00:27
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.

None yet

2 participants