Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 1.12 KB

UPGRADING.md

File metadata and controls

59 lines (43 loc) · 1.12 KB

Upgrading to v1.0

In an initializer add the following

Money.configure do |config|
  config.legacy_default_currency!
  config.legacy_deprecations!
  config.legacy_json_format!
  #...
end

Remove each legacy setting making sure your app functions as expected.

Replace Money.parse with Money::Parser::Fuzzy.parse.

Legacy support

legacy_default_currency!

By enabling this setting your app will accept money object that are missing a currency

Money.new(1) #=> value: 1, currency: XXX

legacy_deprecations!

invalid money values return zero

Money.new('a', 'USD') #=> Money.new(0, 'USD')

invalid currency is ignored

Money.new(1, 'ABCD') #=> Money.new(1)

mathematical operations between objects are allowed

Money.new(1, 'USD') + Money.new(1, 'CAD') #=> Money.new(2, 'USD')

parsing a string with invalid delimiters

Money.parse('123*12') #=> Money.new(123)

legacy_json_format!

to_json will return only the value (no currency)

# with legacy_json_format!
money.to_json #=> "1"

# without
money.to_json #=> { value: 1, currency: 'USD' }