Skip to content

Commit

Permalink
Deprecate Money.default_backend/0 in favour of Money.default_backend!/0
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Dec 31, 2024
1 parent e8b604b commit d4db9b6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

**Note** `ex_money` 5.17.0 and later is supported on Elixir 1.12 and later versions only.

## Money v5.19.0

This is the changelog for Money v5.19.0 released on January 1st, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)

### Deprecations

* `Money.default_backend/0` is deprecated in favor of `Money.default_backend!/0` whose naming better expresses the side effect of an exception being raised if no default backend is configured.

### Bug Fixes

* Surface an error exception if, when starting the exchange rates service, no ex_cldr backend is configured.

## Money v5.18.0

This is the changelog for Money v5.18.0 released on September 18th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/kipcole9/money/tags)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ An optional callback module can also be defined. This module defines a `rates_r
log_failure: :warning,
log_info: :info,
log_success: nil,
json_library: Jason,
json_library: Jason on Elixir up to 1.17, JSON on Elixir 1.18+,
default_cldr_backend: MyApp.Cldr,
exclude_protocol_implementations: []

Expand Down Expand Up @@ -129,7 +129,7 @@ An optional callback module can also be defined. This module defines a `rates_r

* `:retriever_options` is available for exchange rate retriever module developers as a place to add retriever-specific configuration information. This information should be added in the `init/1` callback in the retriever module. See `Money.ExchangeRates.OpenExchangeRates.init/1` for an example.

* `:json_library` determines which json library to be used for decoding. Two common options are `Poison` and `Jason`. The default is `Cldr.Config.json_library/0` which is currently configured by default as `Jason`.
* `:json_library` determines which json library to be used for decoding. Two common options are `Poison` and `Jason`. The default is `Cldr.Config.json_library/0` which will attempt to use `Json` (built in as of Elixir 1.18) or `:json` (built into OTP as of OTP 27).

* `:exclude_protocol_implementations` is a protocol module, or list of protocol modules, that will not be defined by `ex_money`. The default is `[]`. The protocol implementations influenced by this option at `Json.Encoder`, `Phoenix.HTML.Safe` and `Gringotts.Money`.

Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ config :ex_money,
log_failure: :warning,
log_info: :info,
log_success: :info,
json_library: Jason,
# json_library: Jason,
exchange_rates_cache: Money.ExchangeRates.Cache.Dets,
default_cldr_backend: Money.Cldr

Expand Down
19 changes: 10 additions & 9 deletions lib/money.ex
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,14 @@ defmodule Money do
any entries in `:except` are removed from the `:only`
entries.
* `:all`, the default, considers all currencies
* `:all`, the default, considers all currencies.
* `:current` considers those currencies that have a `:to`
date of nil and which also is a known ISO4217 currency
date of nil and which also is a known ISO4217 currency.
* `:historic` is the opposite of `:current`
* `:historic` is the opposite of `:current`.
* `:tender` considers currencies that are legal tender
* `:tender` considers currencies that are legal tender.
* `:unannotated` considers currencies that don't have
"(some string)" in their names. These are usually
Expand Down Expand Up @@ -704,9 +704,10 @@ defmodule Money do
## Arguments
* `money` is any valid `t:Money.t/0` type returned
by `Money.new/2`
by `Money.new/2`.
* `options` is a keyword list of options or a `%Cldr.Number.Format.Options{}` struct
* `options` is a keyword list of options or a `t:Cldr.Number.Format.Options.t/0`
struct.
## Returns
Expand Down Expand Up @@ -736,7 +737,7 @@ defmodule Money do
* `:no_fraction_if_integer` is a boolean which, if `true`, will set `:fractional_digits`
to `0` if the money value is an integer value.
* Any other options are passed to `Cldr.Number.to_string/3`
* Any other options are passed to `Cldr.Number.to_string/3`.
## Examples
Expand Down Expand Up @@ -769,7 +770,7 @@ defmodule Money do
end

def to_string(%Money{} = money, options) when is_list(options) do
default_options = [backend: Money.default_backend(), currency: money.currency]
default_options = [backend: Money.default_backend!(), currency: money.currency]
format_options = Map.get(money, :format_options, [])

options =
Expand Down Expand Up @@ -2992,7 +2993,7 @@ defmodule Money do
"""
end

@doc deprecated: "Use Money.default_backend!/0"
@deprecated "Use Money.default_backend!/0"
def default_backend do
default_backend!()
end
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Money.Mixfile do
use Mix.Project

@version "5.18.1"
@version "5.19.0"

def project do
[
Expand Down
2 changes: 1 addition & 1 deletion test/money_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ defmodule MoneyTest do
Application.put_env(:ex_money, :default_cldr_backend, nil)
Application.put_env(:ex_cldr, :default_backend, Test.Cldr)

assert Money.default_backend() == Test.Cldr
assert Money.default_backend!() == Test.Cldr

Application.put_env(:ex_money, :default_cldr_backend, money_backend)
Application.put_env(:ex_cldr, :default_backend, cldr_backend)
Expand Down

0 comments on commit d4db9b6

Please sign in to comment.