Skip to content

l0.DependencyControl.ConfigView

ConfigView = require "l0.DependencyControl.ConfigView"
local ConfigView = require("l0.DependencyControl.ConfigView")

ConfigView

A view into a hive (nested path) of a ConfigHandler's JSON config file. Holds the defaults-fallthrough machinery and exposes @c / @config / @userConfig. Multiple views on the same file are coordinated through their shared ConfigHandler.

Constructor

configView = ConfigView configHandler, hivePath, defaults
local configView = ConfigView(configHandler, hivePath, defaults)

Creates a view into a hive of the given ConfigHandler.

param type description
configHandler ConfigHandler|nil Backing handler, or nil for an in-memory (orphan) view.
hivePath string|string[] The hive (nested key path) this view targets.
defaults? table Default values for the hive.

Instance methods

delete

configView\delete waitLockTime
configView:delete(waitLockTime)

Removes this view's hive from the config file.

param type description
waitLockTime? number Seconds to wait for the config lock.

Returns:

  • success boolean?
  • err string?

import

configView\import tbl, keys, updateOnly, skipSameLengthTables
configView:import(tbl, keys, updateOnly, skipSameLengthTables)

Copies values from a table or ConfigView into this view's user config.

param type description
tbl? table|ConfigView Source values.
keys? string[] Restrict the copy to these keys.
updateOnly? boolean Only overwrite keys already present in this view.
skipSameLengthTables? boolean Skip array values whose length matches the existing one.

Returns:

  • changesMade boolean

isOverlappingView

configView\isOverlappingView otherView
configView:isOverlappingView(otherView)

Returns whether this view's hive overlaps with another view on the same handler.

param type description
otherView ConfigView

Returns:

  • overlapping boolean? — nil when the views belong to different handlers.
  • err string?

load

configView\load waitLockTime
configView:load(waitLockTime)

Reloads only this view's hive from the config file.

param type description
waitLockTime? number Seconds to wait for the config lock.

Returns:

  • success boolean?
  • err string?

refresh

configView\refresh!
configView:refresh()

Refreshes this view's userConfig from the handler's in-memory config.

Returns:

  • success boolean?
  • err string?

save

configView\save waitLockTime
configView:save(waitLockTime)

Writes this view's hive to the config file.

param type description
waitLockTime? number Seconds to wait for the config lock.

Returns:

  • success boolean?
  • err string?

write

Deprecated — Use save. Retained as an alias for callers written against DepCtrl < 0.7.

configView\write waitLockTime
configView:write(waitLockTime)
param type description
waitLockTime? number Seconds to wait for the config lock.

Returns:

  • success boolean?
  • err string?

setFile

configView\setFile filePath
configView:setFile(filePath)

Attaches this view to a different config file, without loading it (the caller loads separately).

param type description
filePath string Full path to the config file.

Returns:

  • success boolean?
  • err string?

unsetFile

configView\unsetFile!
configView:unsetFile()

Detaches this view from its config file, reverting to an in-memory (orphan) state.

Returns:

  • success boolean

getSectionHandler

configView\getSectionHandler hivePath, defaults, noLoad
configView:getSectionHandler(hivePath, defaults, noLoad)

Returns a ConfigView for another hive of the same config file, sharing this view's handler.

param type description
hivePath string|string[] The hive path within the config file (from the file root, not relative to this view).
defaults? table Default values for the returned view's hive.
noLoad? boolean Skip loading the returned view (the caller loads it separately).

Returns:

Class methods

get

ConfigView\get filePath, hivePath, defaults, logger, noLoad, schemaOpts
ConfigView:get(filePath, hivePath, defaults, logger, noLoad, schemaOpts)

Returns a ConfigView for the given file and hive path, creating a handler if needed.

param type description
filePath string|boolean Config file path, or false for an in-memory (orphan) view.
hivePath string|string[] The hive (nested key path) this view targets.
defaults? table Default values for the hive.
logger? Logger
noLoad? boolean Don't load the file immediately (default false).
schemaOpts? { schemaId: string, migrate: fun(config: table, current?: string, target: string): boolean } Schema id/migration for the backing handler (see ConfigHandler.get); applied only when the handler is first created for this file.

Returns: