Public API of econfig econfig rely on a central gen_server an an ETS ordered-set.
config_name() = atom() | string() | binary()
config_options() = [autoreload | {autoreload, integer} | {change_fun, function()}]
inifile() = string()
inifiles() = [inifile()]
kvs() = [{any(), any()}]
section() = string()
all/1 | get all values of a configuration. |
cfg2list/1 | retrive config as a proplist. |
cfg2list/2 | retrieve config as a proplist. |
delete_value/2 | delete all key/values from a section. |
delete_value/3 | delete a value and persist the change to the file. |
delete_value/4 | delete a value and optionnally persist it. |
get_binary/3 | get a value and convert it to an binary. |
get_binary/4 | get a value and convert it to an binary. |
get_boolean/3 | get a value and convert it to a boolean if possible This method is case-insensitive and recognizes Boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0' a badarg error is raised if the value can't be parsed to a boolean. |
get_boolean/4 | get a value and convert it to a boolean if possible. |
get_float/3 | get a value and convert it to an float. |
get_float/4 | get a value and convert it to an float. |
get_integer/3 | get a value and convert it to an integer. |
get_integer/4 | get a value and convert it to an integer. |
get_list/3 | get a value and convert it to an list. |
get_list/4 | get a value and convert it to an list. |
get_value/2 | get keys/values of a section. |
get_value/3 | get value for a key in a section. |
get_value/4 | get value for a key in a section or return the default value if not set. |
open_config/2 | open or create an ini file an register it. |
open_config/3 | open or create an ini file an register it. |
prefix/2 | get all sections starting by Prefix. |
register_config/2 | register inifiles or config dirs. |
register_config/3 | register inifiles of config dirs with options
For now the only option isautoreload to auto reload the config on
files or dirs changes. |
reload/1 | reload the configuration. |
reload/2 | reload the configuration. |
sections/1 | get all sections of a configuration. |
set_value/3 | set a list of key/value for a section. |
set_value/4 | set a value and persist it to the file. |
set_value/5 | set a value and optionnaly persist it. |
start_autoreload/1 | start the config watcher. |
stop_autoreload/1 | stop the config watcher. |
subscribe/1 | Subscribe to config events for a config named ConfigName |
unregister_config/1 | unregister a conf. |
unsubscribe/1 | Remove all subscribtions to ConfigName events for this process. |
all(ConfigName::config_name()) -> [{section(), [{string(), string()}]}]
get all values of a configuration
cfg2list(ConfigName::config_name()) -> [{section(), [{string(), string()}]}]
retrive config as a proplist
cfg2list(ConfigName::config_name(), GroupKey::string()) -> [{section(), [{string(), string()}]}]
retrieve config as a proplist
delete_value(ConfigName::config_name(), Section::section()) -> ok
delete all key/values from a section
delete_value(ConfigName::config_name(), Section::section(), Key::any()) -> ok
delete a value and persist the change to the file
delete_value(ConfigName::config_name(), Section::section(), Key::any(), Persist::boolean()) -> ok
delete a value and optionnally persist it
get_binary(ConfigName::config_name(), Section::section(), Key::any()) -> Value::binary() | undefined
get a value and convert it to an binary
get_binary(ConfigName::config_name(), Section::section(), Key::any(), Default::binary()) -> Value::binary()
get a value and convert it to an binary
get_boolean(ConfigName::config_name(), Section::section(), Key::any()) -> Value::boolean() | undefined
get a value and convert it to a boolean if possible This method is case-insensitive and recognizes Boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0' a badarg error is raised if the value can't be parsed to a boolean
get_boolean(ConfigName::config_name(), Section::section(), Key::any(), Default::boolean()) -> Value::boolean()
get a value and convert it to a boolean if possible. It fallback to default if not set. This method is case-insensitive and recognizes Boolean values from 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0' a badarg error is raised if the value can't be parsed to a boolean
get_float(ConfigName::config_name(), Section::section(), Key::any()) -> Value::float() | undefined
get a value and convert it to an float
get_float(ConfigName::config_name(), Section::section(), Key::any(), Default::float()) -> Value::float()
get a value and convert it to an float
get_integer(ConfigName::config_name(), Section::section(), Key::any()) -> Value::integer() | undefined
get a value and convert it to an integer
get_integer(ConfigName::config_name(), Section::section(), Key::any(), Default::integer()) -> Value::integer()
get a value and convert it to an integer
get_list(ConfigName::config_name(), Section::section(), Key::any()) -> Value::list() | undefined
get a value and convert it to an list
get_list(ConfigName::config_name(), Section::section(), Key::any(), Default::list()) -> Value::list()
get a value and convert it to an list
get_value(ConfigName::config_name(), Section::string()) -> [{string(), string()}]
get keys/values of a section
get_value(ConfigName::config_name(), Section::section(), Key::any()) -> Value::string() | undefined
get value for a key in a section
get_value(ConfigName::config_name(), Section::section(), Key::any(), Default::any()) -> Value::string()
get value for a key in a section or return the default value if not set
open_config(ConfigName::config_name(), IniFiles::inifiles()) -> ok | {error, any()}
open or create an ini file an register it
open_config(ConfigName::config_name(), IniFiles::inifiles(), Options::config_options()) -> ok | {error, any()}
open or create an ini file an register it. See the register_config function for a list of available functions.
prefix(ConfigName::config_name(), Prefix::string()) -> [{section(), [{string(), string()}]}]
get all sections starting by Prefix
register_config(ConfigName::config_name(), IniFiles::inifiles()) -> ok | {error, any()}
register inifiles or config dirs
register_config(ConfigName::config_name(), IniFiles::inifiles(), Options::config_options()) -> ok | {error, any()}
register inifiles of config dirs with options
For now the only option isautoreload
to auto reload the config on
files or dirs changes.
Configs can also be registererd in the app configuration at startup:
[confs, [{ConfigName, IniFile}, {ConfigName1, IniFiles1, [Options]}, ..]]
Options:
autoreload
: auto reload the config on files or dirs changes{autoreload, Delay}
: autoreload the config file or dir changes. Delay set the time between each scan. Default is 5000 and can be set using thescan_delay
application environement for econfig.
reload(ConfigName::config_name()) -> ok
reload the configuration
reload(ConfigName::config_name(), IniFiles::inifiles()) -> ok
reload the configuration
sections(ConfigName::config_name()) -> [section()]
get all sections of a configuration
set_value(ConfigName::config_name(), Section::section(), KVs::kvs()) -> ok
set a list of key/value for a section
set_value(ConfigName::config_name(), Section::section(), Key::any(), Value::any()) -> ok
set a value and persist it to the file
set_value(ConfigName::config_name(), Section::section(), Key::any(), Value::any(), Persist::boolean()) -> ok
set a value and optionnaly persist it.
start_autoreload(ConfigName::config_name()) -> ok
start the config watcher.
stop_autoreload(ConfigName::config_name()) -> ok
stop the config watcher.
subscribe(ConfigName::config_name()) -> ok
Subscribe to config events for a config named ConfigName
The message received to each subscriber will be of the form:
{config_updated, ConfigName, reload}
{config_updated, ConfigName, registered}
{config_updated, ConfigName, unregistered}
{config_updated, ConfigName, {set, {Section, Key}}
{config_updated, ConfigName, {delete, {Section, Key}}
unregister_config(ConfigName::config_name()) -> ok
unregister a conf
unsubscribe(ConfigName::config_name()) -> ok
Remove all subscribtions to ConfigName events for this process