A simple configuration manager for namespaced modules.
The package can be installed
by adding get_conf
to your list of dependencies in mix.exs
:
{:get_conf, "~> 0.1.0"},
Define your configuration in your config/{env}.exs
:
use Mix.Config
config :app_name, AppName, key: "value"
And access it in your modules. It will go further up the namespace, to find a matching key in the configuration of each module.
GetConf.get_conf(:app_name, AppName, :key)
# => "value"
GetConf.get_conf(:app_name, AppName.Module, :key)
# => "value"
You can also use the GetConf module inside your module, to implement get_conf/1
and set_conf/2
.
defmodule TestModule
use GetConf, otp_app: :app_name
end
"bar" = TestModule.get_conf(:foo)
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/get_conf.