summaryrefslogtreecommitdiffstats
path: root/acf2/model/field.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-10-31 22:51:19 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-10-31 23:10:34 +0200
commitf7f72d6e0652a35308cd0ae8e5561aaa276ff59e (patch)
tree2568fbd641e2e1d90fb54122b23a5d8a69c48136 /acf2/model/field.lua
parent95167c1a1a100bcadd19b3e2f1815d521e4cd4a0 (diff)
downloadaconf-f7f72d6e0652a35308cd0ae8e5561aaa276ff59e.tar.bz2
aconf-f7f72d6e0652a35308cd0ae8e5561aaa276ff59e.tar.xz
model: set netmask using CIDR notation
Diffstat (limited to 'acf2/model/field.lua')
-rw-r--r--acf2/model/field.lua16
1 files changed, 9 insertions, 7 deletions
diff --git a/acf2/model/field.lua b/acf2/model/field.lua
index e09b639..809fdc3 100644
--- a/acf2/model/field.lua
+++ b/acf2/model/field.lua
@@ -82,11 +82,13 @@ end
function M.Field:load(context)
if not context.txn then return setmetatable({}, context) end
- local value = context.txn:get(context.addr)
+ local value = self:_load(context)
if value == nil then return self.default end
return value
end
+function M.Field:_load(context) return context.txn:get(context.addr) end
+
function M.Field:_validate(context, value)
if self.required and value == nil then
raise(context.path, 'Required value not set')
@@ -104,15 +106,15 @@ function M.Field:validate(context, value) end
function M.Field:save(context, value)
if not self.editable then raise(context.path, 'Is not editable') end
- context.txn:set(context.addr, self:_validate(context, value))
+ self:_save(context, self:_validate(context, value))
end
+function M.Field:_save(context, value) context.txn:set(context.addr, value) end
+
function M.Field:validate_saved(context)
self:save(context, self:load(context))
end
-function M.Field:clear(context) context.txn:set(context.addr) end
-
local Primitive = class(M.Field)
@@ -196,7 +198,7 @@ function M.TreeNode:load(context, options)
if context.txn and not (
(
options and options.create
- ) or self.create or context.txn:get(context.addr)
+ ) or self.create or self:_load(context)
) then return end
return self.itype(context, self.iparams)
end
@@ -210,14 +212,14 @@ function M.TreeNode:save(context, value)
return
end
- context.txn:set(context.addr)
+ self:_save(context)
if value then
if type(value) ~= 'table' then
raise(path, 'Cannot assign primitive value')
end
- context.txn:set(context.addr, {})
+ self:_save(context, {})
local new = self:load(context, {create=true})
local errors = err.ErrorDict()