Handle non-list keys in Config.fetch/1
This commit is contained in:
parent
2299bfe4c1
commit
8c57a299b4
2 changed files with 4 additions and 0 deletions
|
@ -32,6 +32,8 @@ def get!(key) do
|
|||
end
|
||||
end
|
||||
|
||||
def fetch(key) when is_atom(key), do: fetch([key])
|
||||
|
||||
def fetch([root_key | keys]) do
|
||||
Enum.reduce_while(keys, Application.fetch_env(:pleroma, root_key), fn
|
||||
key, {:ok, config} when is_map(config) or is_list(config) ->
|
||||
|
|
|
@ -127,9 +127,11 @@ test "fetch/1" do
|
|||
Pleroma.Config.put([:ipsum], dolor: :sit)
|
||||
|
||||
assert Pleroma.Config.fetch([:lorem]) == {:ok, :ipsum}
|
||||
assert Pleroma.Config.fetch(:lorem) == {:ok, :ipsum}
|
||||
assert Pleroma.Config.fetch([:ipsum, :dolor]) == {:ok, :sit}
|
||||
assert Pleroma.Config.fetch([:lorem, :ipsum]) == :error
|
||||
assert Pleroma.Config.fetch([:loremipsum]) == :error
|
||||
assert Pleroma.Config.fetch(:loremipsum) == :error
|
||||
|
||||
Pleroma.Config.delete([:lorem])
|
||||
Pleroma.Config.delete([:ipsum])
|
||||
|
|
Loading…
Reference in a new issue