Add basic configuration management module.
This commit is contained in:
parent
27a06bd440
commit
9b77030d3c
2 changed files with 25 additions and 0 deletions
15
lib/pleroma/config.ex
Normal file
15
lib/pleroma/config.ex
Normal file
|
@ -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
|
10
test/config_test.exs
Normal file
10
test/config_test.exs
Normal file
|
@ -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
|
Loading…
Reference in a new issue