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.lua76
1 files changed, 42 insertions, 34 deletions
diff --git a/aconf/model/node.lua b/aconf/model/node.lua
index 0b4d36d..91f0256 100644
--- a/aconf/model/node.lua
+++ b/aconf/model/node.lua
@@ -135,6 +135,47 @@ function M.TreeNode:init(context, params)
end
+ function mt._search(path, prefix)
+ if #path == 0 then return {{path=prefix, value=self}} end
+
+ local mt = getmetatable(self)
+
+ local name = path[1]
+ table.remove(path, 1)
+
+ local function collect(name)
+ local next = mt.load(name, {dereference=false})
+ if not next then return {} end
+
+ if isinstance(next, M.TreeNode) then
+ return getmetatable(next)._search(
+ copy(path), pth.join(prefix, name)
+ )
+ end
+
+ assert(#path == 0)
+ return {
+ {
+ value=next,
+ deleted=function(path) mt.member(name):deleted(path) end
+ }
+ }
+ end
+
+ if name == pth.wildcard then
+ local res = {}
+ for _, member in ipairs(mt.members()) do
+ util.extend(res, collect(member))
+ end
+ return res
+ end
+
+ return collect(name)
+ end
+
+ function mt.search(path) return mt._search(pth.split(path), '') end
+
+
local permissions = {}
function mt._has_permission(permission) end
@@ -221,39 +262,6 @@ function M.TreeNode:init(context, params)
mt.txn.validable[mt.path] = mt.addr
end
-function M.TreeNode:search_refs(path)
- if type(path) == 'string' then path = pth.split(path) end
-
- if #path == 0 then return {} end
-
- local mt = getmetatable(getmetatable(self).escalate)
-
- local name = path[1]
- table.remove(path, 1)
-
- local function collect(name)
- local next = mt.load(name, {dereference=false})
- if not next then return {} end
-
- local member = mt.member(name)
- if member.deleted then return {member} end
-
- return isinstance(next, M.TreeNode) and M.TreeNode.search_refs(
- next, path
- ) or {}
- end
-
- if name == pth.wildcard then
- local res = {}
- for _, member in ipairs(mt.members()) do
- util.extend(res, collect(member))
- end
- return res
- end
-
- return collect(name)
-end
-
M.Collection = class(M.TreeNode)
@@ -263,7 +271,6 @@ function M.Collection:init(context, params)
)
self.init = nil
- self.search_refs = nil
local mt = getmetatable(self)
local field = M.BoundMember(self, pth.wildcard, params.field)
@@ -447,6 +454,7 @@ for _, mf in ipairs{
'parent',
'path',
'save',
+ 'search',
'topology'
} do M[mf] = meta_func(mf) end