Skip to content

Commit 007b692

Browse files
committed
Allow a supervisor name to be given to Money.ExchangeRates.Supervisor.stop
1 parent 4b9c097 commit 007b692

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This is the changelog for Money v5.2.1 released on June 23rd, 2020. For older c
66

77
* Configure the `Money.Application` supervisor via the arguments to `Money.Application.start/2` and configure defaults in `mix.exs`. This permits different restart strategies and names.
88

9+
* Add `Money.ExchangeRates.Supervisor.default_supervisor/0` to return the name of the default supervisor which is `Money.Supervisor`
10+
11+
* Change `Money.ExchangeRates.Supervisor.stop/0` to become `Money.ExchangeRates.Supervisor.stop/{0, 1}` allowing the supervisor name to be passed in. The default is `Money.ExchangeRates.Supervisor.default_supervisor/0`
12+
913
### Bug Fixes
1014

1115
* Add back the name of the Application supervisor, `Money.Supervisor`. Thanks for the report of the regression to @jeroenvisser101. Fixes #117.

lib/money/exchange_rates/exchange_rates_supervisor.ex

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ defmodule Money.ExchangeRates.Supervisor do
5252
@doc """
5353
Stop the Money.ExchangeRates.Supervisor.
5454
55-
The Money.ExchangeRates.Supervisor is always started
56-
with `ex_money` starts even if the config key
57-
`:auto_start_exchange_rates_service` is set to `false`.
55+
Unless `ex_money` is configured in `mix.exs` as
56+
`rumtime: false`, the Money.ExchangeRates.Supervisor
57+
is always started when `ex_money` starts even if the
58+
config key `:auto_start_exchange_rates_service` is
59+
set to `false`.
60+
5861
5962
In some instances an application may require the
6063
`Money.ExchangeRates.Supervisor` to be started under
@@ -71,8 +74,21 @@ defmodule Money.ExchangeRates.Supervisor do
7174
from within the callback module" for an eanple of how
7275
to configure the supervisor in this case.
7376
"""
74-
def stop do
75-
Supervisor.terminate_child(Money.Supervisor, __MODULE__)
77+
def stop(supervisor \\ default_supervisor()) do
78+
Supervisor.terminate_child(supervisor, __MODULE__)
79+
end
80+
81+
@doc """
82+
Returns the name of the default supervisor
83+
which is `Money.Supervisor`
84+
85+
"""
86+
def default_supervisor do
87+
{_, options} =
88+
Application.spec(:ex_money)
89+
|> Keyword.get(:mod)
90+
91+
Keyword.get(options, :name)
7692
end
7793

7894
@doc false

test/application_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ defmodule Money.Application.Test do
55
{_app, options} = Application.spec(:ex_money) |> Keyword.get(:mod)
66
assert options == [strategy: :one_for_one, name: Money.Supervisor]
77
end
8+
9+
test "default supervisor name" do
10+
assert Money.ExchangeRates.Supervisor.default_supervisor == Money.Supervisor
11+
end
812
end

0 commit comments

Comments
 (0)