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

BigDecimal not working with Ruby 2.7+ because #new was removed #216

Open
sumirolabs opened this issue Jun 26, 2023 · 3 comments
Open

BigDecimal not working with Ruby 2.7+ because #new was removed #216

sumirolabs opened this issue Jun 26, 2023 · 3 comments

Comments

@sumirolabs
Copy link

BigDecimal#new has been marked for deprecation for awhile and it looks like it finally happened in Ruby 2.7? This broke our configuration that used #new as the parser:

element :payment, BigDecimal, :tag => 'payment', :parser => :new

I have been able to register a new SupportedType and get the new syntax working:

module HappyMapper
  module SupportedTypes
    register_type BigDecimal do |value|
      BigDecimal(value) if value && !value.empty?
    end
  end
end

Is the right approach or am I missing some other way to solve this issue?

@mvz
Copy link
Owner

mvz commented Jun 30, 2023

Yes, I think that's the best way if you want to have the exact same behavior.

An alternative option is to parse using BigDecimal.interpret_loosely. That method is a bit more forgiving so it will accept "4.2 hello", whereas BigDecimal() will not:

element :payment, BigDecimal, :tag => 'payment', :parser => :interpret_loosely

@sumirolabs
Copy link
Author

Do you think this new type should be merged into Happymapper? I can make a PR

@mvz
Copy link
Owner

mvz commented Jul 4, 2023

Yes, @sumirolabs that would be great!

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

No branches or pull requests

2 participants