summaryrefslogtreecommitdiffstats
path: root/aconf/model/field.lua
diff options
context:
space:
mode:
Diffstat (limited to 'aconf/model/field.lua')
-rw-r--r--aconf/model/field.lua36
1 files changed, 24 insertions, 12 deletions
diff --git a/aconf/model/field.lua b/aconf/model/field.lua
index f1236aa..cd849e2 100644
--- a/aconf/model/field.lua
+++ b/aconf/model/field.lua
@@ -3,7 +3,8 @@ Copyright (c) 2012-2016 Kaarle Ritvanen
See LICENSE file for license details
--]]
---- @module aconf.model
+--- Alpine Configurator data model.
+-- @module aconf.model
local M = {}
local err = require('aconf.error')
@@ -57,6 +58,14 @@ function M.conv_filter(filter)
end
+--- Overview of field classes. In the Alpine Configurator object
+-- system, classes are instantiated by invoking the Lua table
+-- representing the class as the constructor. There are a number of
+-- [pre-defined field classes](#Field_classes). More field classes may
+-- be defined by extending them using @{object.class} and overriding
+-- the appropriate methods described in this section. All field class
+-- constructors accept one [argument](#Field_constructor_parameters).
+-- @section Field
M.Field = class(M.Member)
function M.Field:init(params)
@@ -185,6 +194,13 @@ function M.Field:_load(context)
if value ~= nil then return self:decode(context, value) end
end
+--- transform the value's back-end representation to data model
+-- representation. The default implementation is the identity
+-- transformation.
+-- @function decode
+-- @param context transaction context
+-- @tparam primitive value back-end representation
+-- @treturn primitive data model representation
function M.Field:decode(context, value) return value end
function M.Field:_validate(context, value)
@@ -236,6 +252,13 @@ function M.Field:_save(context, value)
context.txn:set(context.addr, value)
end
+--- transform the value's data model representation to back-end
+-- representation. The default implementation is the identity
+-- transformation.
+-- @function encode
+-- @param context transaction context
+-- @tparam primitive value data model representation
+-- @treturn primitive back-end representation
function M.Field:encode(context, value) return value end
function M.Field:validate_saved(context)
@@ -264,8 +287,6 @@ function Primitive:validate(context, value)
end
---- string field.
--- @fcons String
M.String = class(Primitive)
function M.String:init(params)
@@ -320,8 +341,6 @@ function M.Integer:validate(context, value)
end
---- boolean field.
--- @fcons Boolean
M.Boolean = class(Primitive)
function M.Boolean:init(params)
@@ -398,13 +417,6 @@ function M.TreeNode:validate_saved(context)
end
---- model field. The value of this field is a [model
--- object](#Model_objects) conforming to the specified model. A model
--- field with default parameters is implicitly created when a model is
--- used in lieu of a field.
--- @fcons Model
--- @param model (<i>[&lt;Model&gt;](#new)</i>) model describing the
--- structure of the model objects
M.Model = class(M.TreeNode)
function M.Model:init(params)