2019-03-22 10:53:38 +01:00
|
|
|
defmodule Mobilizon.CommonConfig do
|
2019-03-22 13:58:19 +01:00
|
|
|
@moduledoc """
|
|
|
|
Instance configuration wrapper
|
|
|
|
"""
|
2019-03-22 10:53:38 +01:00
|
|
|
|
2019-03-22 13:58:19 +01:00
|
|
|
def registrations_open?() do
|
|
|
|
instance_config()
|
|
|
|
|> get_in([:registrations_open])
|
|
|
|
|> to_bool
|
|
|
|
end
|
|
|
|
|
|
|
|
def instance_name() do
|
|
|
|
instance_config()
|
|
|
|
|> get_in([:name])
|
|
|
|
end
|
2019-03-22 10:53:38 +01:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
def instance_description() do
|
|
|
|
instance_config()
|
|
|
|
|> get_in([:description])
|
|
|
|
end
|
|
|
|
|
2019-03-22 10:53:38 +01:00
|
|
|
defp instance_config(), do: Application.get_env(:mobilizon, :instance)
|
2019-03-22 13:58:19 +01:00
|
|
|
|
|
|
|
defp to_bool(v), do: v == true or v == "true" or v == "True"
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
def get(key), do: get(key, nil)
|
|
|
|
|
|
|
|
def get([key], default), do: get(key, default)
|
|
|
|
|
|
|
|
def get([parent_key | keys], default) do
|
|
|
|
case :mobilizon
|
|
|
|
|> Application.get_env(parent_key)
|
|
|
|
|> get_in(keys) do
|
|
|
|
nil -> default
|
|
|
|
any -> any
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key, default) do
|
|
|
|
Application.get_env(:mobilizon, key, default)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get!(key) do
|
|
|
|
value = get(key, nil)
|
|
|
|
|
|
|
|
if value == nil do
|
|
|
|
raise("Missing configuration value: #{inspect(key)}")
|
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def put([key], value), do: put(key, value)
|
|
|
|
|
|
|
|
def put([parent_key | keys], value) do
|
|
|
|
parent =
|
|
|
|
Application.get_env(:mobilizon, parent_key)
|
|
|
|
|> put_in(keys, value)
|
|
|
|
|
|
|
|
Application.put_env(:mobilizon, parent_key, parent)
|
|
|
|
end
|
|
|
|
|
|
|
|
def put(key, value) do
|
|
|
|
Application.put_env(:mobilizon, key, value)
|
|
|
|
end
|
2019-03-22 10:53:38 +01:00
|
|
|
end
|