summaryrefslogtreecommitdiffstats
path: root/aconf/model/node.lua
diff options
context:
space:
mode:
Diffstat (limited to 'aconf/model/node.lua')
-rw-r--r--aconf/model/node.lua28
1 files changed, 19 insertions, 9 deletions
diff --git a/aconf/model/node.lua b/aconf/model/node.lua
index 4f09c99..a9854ce 100644
--- a/aconf/model/node.lua
+++ b/aconf/model/node.lua
@@ -5,7 +5,8 @@ See LICENSE file for license details
local M = {}
-local raise = require('aconf.error').raise
+local err = require('aconf.error')
+local raise = err.raise
local object = require('aconf.object')
local class = object.class
@@ -305,7 +306,22 @@ function M.Collection:init(context, params)
return res
end
- function mt.members() return mt.txn:get(mt.addr) or {} end
+ local function validate_key(k)
+ if params.key then
+ local kf = M.BoundMember(self, k, object.toinstance(params.key))
+ if kf:normalize(k) ~= k then
+ raise(mt.path, 'Invalid member name: '..k)
+ end
+ kf:validate(k)
+ end
+ end
+
+ function mt.members()
+ return util.filter(
+ function(k) return err.call(validate_key, k) end,
+ mt.txn:get(mt.addr) or {}
+ )
+ end
function mt.__len() return #mt.members() end
@@ -339,13 +355,7 @@ function M.Collection:init(context, params)
else mt.check_permission('modify') end
end
- if params.key then
- local kf = M.BoundMember(self, k, object.toinstance(params.key))
- if kf:normalize(k) ~= k then
- raise(mt.path, 'Invalid member name: '..k)
- end
- kf:validate(k)
- end
+ validate_key(k)
mt.member(k):save(v)
end