Merge branch 'stable' into stable-sync/2.1.1
[akkoma] / lib / pleroma / config / holder.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Config.Holder do
6 @config Pleroma.Config.Loader.default_config()
7
8 @spec save_default() :: :ok
9 def save_default do
10 default_config =
11 if System.get_env("RELEASE_NAME") do
12 release_config =
13 [:code.root_dir(), "releases", System.get_env("RELEASE_VSN"), "releases.exs"]
14 |> Path.join()
15 |> Pleroma.Config.Loader.read()
16
17 Pleroma.Config.Loader.merge(@config, release_config)
18 else
19 @config
20 end
21
22 Pleroma.Config.put(:default_config, default_config)
23 end
24
25 @spec default_config() :: keyword()
26 def default_config, do: get_default()
27
28 @spec default_config(atom()) :: keyword()
29 def default_config(group), do: Keyword.get(get_default(), group)
30
31 @spec default_config(atom(), atom()) :: keyword()
32 def default_config(group, key), do: get_in(get_default(), [group, key])
33
34 defp get_default, do: Pleroma.Config.get(:default_config)
35 end