Skip to content

Latest commit

 

History

History
503 lines (309 loc) · 16 KB

econfig.md

File metadata and controls

503 lines (309 loc) · 16 KB

Module econfig

Public API of econfig econfig rely on a central gen_server an an ETS ordered-set.

Data Types


config_name() = atom() | string() | binary()

config_options() = [autoreload | {autoreload, integer} | {change_fun, function()}]

inifile() = string()

inifiles() = [inifile()]

kvs() = [{any(), any()}]

section() = string()

Function Index

all/1get all values of a configuration.
cfg2list/1retrive config as a proplist.
cfg2list/2retrieve config as a proplist.
delete_value/2delete all key/values from a section.
delete_value/3delete a value and persist the change to the file.
delete_value/4delete a value and optionnally persist it.
get_binary/3get a value and convert it to an binary.
get_binary/4get a value and convert it to an binary.
get_boolean/3get 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/4get a value and convert it to a boolean if possible.
get_float/3get a value and convert it to an float.
get_float/4get a value and convert it to an float.
get_integer/3get a value and convert it to an integer.
get_integer/4get a value and convert it to an integer.
get_list/3get a value and convert it to an list.
get_list/4get a value and convert it to an list.
get_value/2get keys/values of a section.
get_value/3get value for a key in a section.
get_value/4get value for a key in a section or return the default value if not set.
open_config/2open or create an ini file an register it.
open_config/3open or create an ini file an register it.
prefix/2get all sections starting by Prefix.
register_config/2register inifiles or config dirs.
register_config/3register inifiles of config dirs with options For now the only option isautoreload to auto reload the config on files or dirs changes.
reload/1reload the configuration.
reload/2reload the configuration.
sections/1get all sections of a configuration.
set_value/3set a list of key/value for a section.
set_value/4set a value and persist it to the file.
set_value/5set a value and optionnaly persist it.
start_autoreload/1start the config watcher.
stop_autoreload/1stop the config watcher.
subscribe/1Subscribe to config events for a config named ConfigName
unregister_config/1unregister a conf.
unsubscribe/1Remove all subscribtions to ConfigName events for this process.

Function Details

all/1


all(ConfigName::config_name()) -> [{section(), [{string(), string()}]}]

get all values of a configuration

cfg2list/1


cfg2list(ConfigName::config_name()) -> [{section(), [{string(), string()}]}]

retrive config as a proplist

cfg2list/2


cfg2list(ConfigName::config_name(), GroupKey::string()) -> [{section(), [{string(), string()}]}]

retrieve config as a proplist

delete_value/2


delete_value(ConfigName::config_name(), Section::section()) -> ok

delete all key/values from a section

delete_value/3


delete_value(ConfigName::config_name(), Section::section(), Key::any()) -> ok

delete a value and persist the change to the file

delete_value/4


delete_value(ConfigName::config_name(), Section::section(), Key::any(), Persist::boolean()) -> ok

delete a value and optionnally persist it

get_binary/3


get_binary(ConfigName::config_name(), Section::section(), Key::any()) -> Value::binary() | undefined

get a value and convert it to an binary

get_binary/4


get_binary(ConfigName::config_name(), Section::section(), Key::any(), Default::binary()) -> Value::binary()

get a value and convert it to an binary

get_boolean/3


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/4


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/3


get_float(ConfigName::config_name(), Section::section(), Key::any()) -> Value::float() | undefined

get a value and convert it to an float

get_float/4


get_float(ConfigName::config_name(), Section::section(), Key::any(), Default::float()) -> Value::float()

get a value and convert it to an float

get_integer/3


get_integer(ConfigName::config_name(), Section::section(), Key::any()) -> Value::integer() | undefined

get a value and convert it to an integer

get_integer/4


get_integer(ConfigName::config_name(), Section::section(), Key::any(), Default::integer()) -> Value::integer()

get a value and convert it to an integer

get_list/3


get_list(ConfigName::config_name(), Section::section(), Key::any()) -> Value::list() | undefined

get a value and convert it to an list

get_list/4


get_list(ConfigName::config_name(), Section::section(), Key::any(), Default::list()) -> Value::list()

get a value and convert it to an list

get_value/2


get_value(ConfigName::config_name(), Section::string()) -> [{string(), string()}]

get keys/values of a section

get_value/3


get_value(ConfigName::config_name(), Section::section(), Key::any()) -> Value::string() | undefined

get value for a key in a section

get_value/4


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/2


open_config(ConfigName::config_name(), IniFiles::inifiles()) -> ok | {error, any()}

open or create an ini file an register it

open_config/3


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/2


prefix(ConfigName::config_name(), Prefix::string()) -> [{section(), [{string(), string()}]}]

get all sections starting by Prefix

register_config/2


register_config(ConfigName::config_name(), IniFiles::inifiles()) -> ok | {error, any()}

register inifiles or config dirs

register_config/3


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 the scan_delay application environement for econfig.

reload/1


reload(ConfigName::config_name()) -> ok

reload the configuration

reload/2


reload(ConfigName::config_name(), IniFiles::inifiles()) -> ok

reload the configuration

sections/1


sections(ConfigName::config_name()) -> [section()]

get all sections of a configuration

set_value/3


set_value(ConfigName::config_name(), Section::section(), KVs::kvs()) -> ok

set a list of key/value for a section

set_value/4


set_value(ConfigName::config_name(), Section::section(), Key::any(), Value::any()) -> ok

set a value and persist it to the file

set_value/5


set_value(ConfigName::config_name(), Section::section(), Key::any(), Value::any(), Persist::boolean()) -> ok

set a value and optionnaly persist it.

start_autoreload/1


start_autoreload(ConfigName::config_name()) -> ok

start the config watcher.

stop_autoreload/1


stop_autoreload(ConfigName::config_name()) -> ok

stop the config watcher.

subscribe/1


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/1


unregister_config(ConfigName::config_name()) -> ok

unregister a conf

unsubscribe/1


unsubscribe(ConfigName::config_name()) -> ok

Remove all subscribtions to ConfigName events for this process