2018-11-06 15:00:48 +00:00
|
|
|
defmodule Pleroma.Config do
|
2018-11-06 18:34:57 +00:00
|
|
|
defmodule Error do
|
|
|
|
defexception [:message]
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key), do: get(key, nil)
|
|
|
|
|
|
|
|
def get([key], default), do: get(key, default)
|
2018-11-06 15:00:48 +00:00
|
|
|
|
2018-11-06 18:34:57 +00:00
|
|
|
def get([parent_key | keys], default) do
|
2018-11-06 15:00:48 +00:00
|
|
|
Application.get_env(:pleroma, parent_key)
|
2018-11-06 18:34:57 +00:00
|
|
|
|> get_in(keys) || default
|
2018-11-06 15:00:48 +00:00
|
|
|
end
|
|
|
|
|
2018-11-06 18:34:57 +00:00
|
|
|
def get(key, default) do
|
|
|
|
Application.get_env(:pleroma, key, default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get!(key) do
|
|
|
|
value = get(key, nil)
|
|
|
|
|
|
|
|
if value == nil do
|
|
|
|
raise(Error, message: "Missing configuration value: #{inspect(key)}")
|
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
2018-11-06 15:00:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def put([key], value), do: put(key, value)
|
|
|
|
|
|
|
|
def put([parent_key | keys], value) do
|
|
|
|
parent =
|
|
|
|
Application.get_env(:pleroma, parent_key)
|
|
|
|
|> put_in(keys, value)
|
|
|
|
|
|
|
|
Application.put_env(:pleroma, parent_key, parent)
|
|
|
|
end
|
|
|
|
|
|
|
|
def put(key, value) do
|
|
|
|
Application.put_env(:pleroma, key, value)
|
|
|
|
end
|
|
|
|
end
|