Merge branch 'config-delete' into 'develop'
Add Pleroma.Config.delete/1 See merge request pleroma/pleroma!484
This commit is contained in:
commit
e99bab8f27
2 changed files with 29 additions and 0 deletions
|
@ -39,4 +39,18 @@ def put([parent_key | keys], value) do
|
|||
def put(key, value) do
|
||||
Application.put_env(:pleroma, key, value)
|
||||
end
|
||||
|
||||
def delete([key]), do: delete(key)
|
||||
|
||||
def delete([parent_key | keys]) do
|
||||
{_, parent} =
|
||||
Application.get_env(:pleroma, parent_key)
|
||||
|> get_and_update_in(keys, fn _ -> :pop end)
|
||||
|
||||
Application.put_env(:pleroma, parent_key, parent)
|
||||
end
|
||||
|
||||
def delete(key) do
|
||||
Application.delete_env(:pleroma, key)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,4 +53,19 @@ test "put/2 with a list of keys" do
|
|||
assert Pleroma.Config.get([:instance, :config_test]) == true
|
||||
assert Pleroma.Config.get([:instance, :config_nested_test, :x]) == true
|
||||
end
|
||||
|
||||
test "delete/1 with a key" do
|
||||
Pleroma.Config.put([:delete_me], :delete_me)
|
||||
Pleroma.Config.delete([:delete_me])
|
||||
assert Pleroma.Config.get([:delete_me]) == nil
|
||||
end
|
||||
|
||||
test "delete/2 with a list of keys" do
|
||||
Pleroma.Config.put([:delete_me], hello: "world", world: "Hello")
|
||||
Pleroma.Config.delete([:delete_me, :world])
|
||||
assert Pleroma.Config.get([:delete_me]) == [hello: "world"]
|
||||
Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
|
||||
Pleroma.Config.delete([:delete_me, :delete_me, :world])
|
||||
assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue