diff options
author | lain <lain@soykaf.club> | 2018-09-08 14:01:00 +0200 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2018-11-01 09:01:03 +0000 |
commit | 9b77030d3ca9530fbea05aeb2191915bb1c454cb (patch) | |
tree | be961df11df85ef889f13ec1c3d548a51b290708 | |
parent | 27a06bd440eeb6b8683a42f73a2ffd1a23a25b63 (diff) | |
download | pleroma-9b77030d3ca9530fbea05aeb2191915bb1c454cb.tar.gz |
Add basic configuration management module.
-rw-r--r-- | lib/pleroma/config.ex | 15 | ||||
-rw-r--r-- | test/config_test.exs | 10 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex new file mode 100644 index 000000000..510d8d498 --- /dev/null +++ b/lib/pleroma/config.ex @@ -0,0 +1,15 @@ +defmodule Pleroma.Config do + use Agent + + def start_link(initial) do + Agent.start_link(fn -> initial end, name: __MODULE__) + end + + def get(path) do + Agent.get(__MODULE__, Kernel, :get_in, [path]) + end + + def put(path, value) do + Agent.update(__MODULE__, Kernel, :put_in, [path, value]) + end +end diff --git a/test/config_test.exs b/test/config_test.exs new file mode 100644 index 000000000..6d0f0a2d4 --- /dev/null +++ b/test/config_test.exs @@ -0,0 +1,10 @@ +defmodule Pleroma.ConfigTest do + use Pleroma.DataCase + alias Pleroma.Config + + test "get returns the item at the path if there is one" do + Config.put([:instance, :name], "Plemora") + assert Config.get([:instance, :name]) == "Plemora" + assert Config.get([:unknown]) == nil + end +end |