From 1e4cb26264f67b5fe8e3e55e17d1ad785c137f24 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Sun, 22 Feb 2015 00:08:53 +0200 Subject: model: scattered lists --- aconf/transaction/base.lua | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'aconf/transaction/base.lua') diff --git a/aconf/transaction/base.lua b/aconf/transaction/base.lua index f40dcca..1886fd9 100644 --- a/aconf/transaction/base.lua +++ b/aconf/transaction/base.lua @@ -11,7 +11,7 @@ local object = require('aconf.object') local class = object.class local address = require('aconf.path.address') -local copy = require('aconf.util').copy +local util = require('aconf.util') -- TODO each transaction backend (i.e. persistence manager or -- transaction proper) should be implemented as a thread or have its @@ -107,7 +107,7 @@ function M.Transaction:get(path) if self.deleted[path] then return nil, self.mod_time[path] end for _, tbl in ipairs{self.added, self.modified} do if tbl[path] ~= nil then - return copy(tbl[path]), self.mod_time[path] + return util.copy(tbl[path]), self.mod_time[path] end end @@ -116,6 +116,35 @@ function M.Transaction:get(path) return value, timestamp end +function M.Transaction:expand(path) + local prefix = {} + path = address.split(path) + + while path[1] do + local comp = path[1] + table.remove(path, 1) + + if comp == address.wildcard then + local p = address.join('/', table.unpack(prefix)) + local res = {} + + local children = self:get(p) or {} + table.sort(children) + for _, child in ipairs(children) do + util.extend( + res, self:expand(address.join(p, child, table.unpack(path))) + ) + end + + return res + end + + table.insert(prefix, comp) + end + + return {address.join('/', table.unpack(prefix))} +end + function M.Transaction:_set_multiple(mods) local function set(path, value, new) -- cgit v1.2.3