Developer_release_1.4.0

Class mint.bindings.configuration_wrapper

Work with configuration.

Usage:

    local mint = require 'mint'
    local cfg = mint:configuration()
    local log = cfg:logger('my_app')
    log:info('Hello world!')
    

Methods

cfg:add_or_update_config (path, value) Add new or update existing field in the current configuration.
cfg:add_to_config (path, value) Add new field to the current configuration.
cfg:contain_field (path) Check if the field is exist in the current configuration.
cfg:get_config () Get current config as table.
cfg:get_config_field (fieldNameOrPath) Get field value from the current config.
cfg:get_log_files () Get log files.
cfg:is_first_run () Check if current config exists.
cfg:logger ([logger_name='macnica_logger']) Create logger or return existing one.
cfg:patch_config (patch) Apply updates to config and save.
cfg:reset_config () Remove current config.
cfg:reset_logs () Reset logs.
cfg:subscribe () Subscribe on config changes events.
cfg:update_config (path, value) Update current configuration field.


Methods

cfg:add_or_update_config (path, value)
Add new or update existing field in the current configuration.

Parameters:

  • path string JSON path to the configuration field
  • value string, number, boolean, table or nil Field value

Returns:

    true (on success)

Or

  1. nil
  2. string Error message (on failure)

Usage:

    cfg:add_or_update_config('/log/max_day_file_size', 250)
    cfg:add_or_update_config(
        '/applications/com.example.acme.temperature_checker',
        {
          __app_version = '1.0.0';
          TOO_HOT_THRESHOLD = 55;
          EXTREMELY_HOT_THRESHOLD = 80;
          EXTRA_CUSTOM_DATA =
          {
            table1 = { 1, 2, 3, 4, 5 };
            string = 'str';
            number = 12345;
          };
        }
      )
cfg:add_to_config (path, value)
Add new field to the current configuration.

Parameters:

  • path string JSON path to the new configuration field
  • value string, number, boolean, table or nil Field value

Returns:

    true (on success)

Or

  1. nil
  2. string Error message (on failure)

Usage:

    cfg:add_to_config('/log/max_day_file_size', 250)
    cfg:add_to_config(
        '/applications/com.example.acme.temperature_checker',
        {
          __app_version = '1.0.0';
          TOO_HOT_THRESHOLD = 55;
          EXTREMELY_HOT_THRESHOLD = 80;
          EXTRA_CUSTOM_DATA =
          {
            table1 = { 1, 2, 3, 4, 5 };
            string = 'str';
            number = 12345;
          };
        }
      )
cfg:contain_field (path)
Check if the field is exist in the current configuration.

Parameters:

  • path string JSON path to the configuration field

Returns:

    boolean Existence status (on success)

Or

  1. nil
  2. string Error message (on failure)

Usage:

    local is_found = cfg:contain_field('/log/max_day_file_size')
cfg:get_config ()
Get current config as table.

Returns:

    table Current config as table

Usage:

    cfg:get_config()
cfg:get_config_field (fieldNameOrPath)
Get field value from the current config. You also can get a field value by using index/property accessor operator directly on the configuration instance. See usages below.

Parameters:

  • fieldNameOrPath string Full JSON path to the field

Returns:

    string, number, boolean, table or nil Field value (on success)

Or

  1. nil
  2. string Error message (on failure)

Usage:

    local device_name = cfg:get_config_field('/userspace/general/device_name')
cfg:get_log_files ()
Get log files.

Returns:

    string[] Paths to log files

Usage:

    local log_files = cfg:get_log_files()
cfg:is_first_run ()
Check if current config exists.

Returns:

    bool true if no config file is found (first run)

Usage:

    local mint_first_run = cfg:is_first_run()
cfg:logger ([logger_name='macnica_logger'])
Create logger or return existing one.

Parameters:

  • logger_name string Name of the logger. Also will be used as log messages prefix. If the name starts with "~" the log messages will be echoed to stdio. (default 'macnica_logger')

Returns:

    Logger instance

Usage:

    local log = cfg:logger('my_logger')
cfg:patch_config (patch)
Apply updates to config and save. (

Parameters:

  • patch table Array of JSON patches

Returns:

    true (on success)

Or

  1. nil
  2. string Error message (on failure)

Usage:

    cfg:patch_config({
      {
        op = 'replace';
        path = '/log/max_file_size';
        value = 250;
      }
    })
cfg:reset_config ()
Remove current config.

Returns:

    None

Usage:

    cfg:reset_config()
cfg:reset_logs ()
Reset logs.

Returns:

    None

Usage:

    cfg:reset_logs()
cfg:subscribe ()
Subscribe on config changes events.

Usage:

    cfg:subscribe('/media', function (key, event, value)
      print('media configuration changed: key: ' .. tostring(key))
      print('media configuration changed: event: ' .. tostring(event))
      print('media configuration changed: value: ' .. tpretty(value))
    end)
cfg:update_config (path, value)
Update current configuration field.

Parameters:

  • path string JSON path to the configuration node
  • value string, number, boolean, table or nil Node value to set

Returns:

    true (on success)

Or

  1. nil
  2. string Error message (on failure)

Usage:

    cfg:update_config('/log/max_file_size', 250)
    cfg:update_config(
        '/applications/com.example.acme.temperature_checker',
        {
          __app_version = '1.0.0';
          TOO_HOT_THRESHOLD = 55;
          EXTREMELY_HOT_THRESHOLD = 80;
          EXTRA_CUSTOM_DATA =
          {
            table1 = { 1, 2, 3, 4, 5 };
            string = 'str';
            number = 12345;
          };
        }
      )
generated by LDoc 1.4.6 Last updated 1980-01-01 00:00:00