Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 999 Bytes

README.md

File metadata and controls

40 lines (29 loc) · 999 Bytes

Sweetconfig

Build Status

Place configuration YAML files in priv/ directory of your root application. Add following section to your config.exs file:

config :sweetconfig,
	app: :name_of_your_application

Include :sweetconfig into your app deps list.

Now you can read configuration at any point in your app like this:

Sweetconfig.get :somekey
Sweetconfig.get [:somekey, :somesubkey]
Sweetconfig.get :whatever, :default_value

Subscribing to changes

It is possible to get notifications when a certain config value has changed during config reload.

path = [:root, :some, "nested", "value"]
Sweetconfig.subscribe path, self()
Sweetconfig.Utils.load_configs  # assume this changes the value at the path above
receive do
  {Sweetconfig.Pubsub, ^path, {:changed, old, new}} ->
    IO.inspect old
    IO.inspect new
end