diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-03-24 15:31:06 +0200 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-03-25 09:02:58 +0200 |
commit | c1993c6f11df64f53239e246412e3ff09927651d (patch) | |
tree | e536a395644fdd89296962c0b9dd0b0ea7fd0737 /aconf/model | |
parent | 751f019580e210ff22fc1ac0eea72cece854534a (diff) | |
download | aconf-c1993c6f11df64f53239e246412e3ff09927651d.tar.bz2 aconf-c1993c6f11df64f53239e246412e3ff09927651d.tar.xz |
model: split TreeNode fetch function into two
Diffstat (limited to 'aconf/model')
-rw-r--r-- | aconf/model/node.lua | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/aconf/model/node.lua b/aconf/model/node.lua index 50edac6..0ce5016 100644 --- a/aconf/model/node.lua +++ b/aconf/model/node.lua @@ -74,15 +74,8 @@ function M.TreeNode:init(context, params) function mt.get(k, options) return mt.load(k, options) end - function mt.fetch(path, create) - if type(path) == 'string' then - if pth.is_absolute(path) and mt.path > '/' then - assert(not create) - return mt.txn:fetch(path, mt.privileged) - end - path = pth.split(path) - end + function mt._fetch(path, create) if #path == 0 then return self end local name = path[1] @@ -92,7 +85,7 @@ function M.TreeNode:init(context, params) if not mt.parent then raise(mt.path, 'Root object does not have parent') end - return getmetatable(mt.parent).fetch(path, create) + return getmetatable(mt.parent)._fetch(path, create) end if not mt.member(name) then @@ -114,9 +107,18 @@ function M.TreeNode:init(context, params) raise(pth.join(mt.path, name), 'Is a primitive value') end - return getmetatable(next).fetch(path, create) + return getmetatable(next)._fetch(path, create) + end + + function mt.fetch(path, create) + if pth.is_absolute(path) and mt.path > '/' then + assert(not create) + return mt.txn:fetch(path, mt.privileged) + end + return mt._fetch(pth.split(path), create) end + function mt.has_permission(permission) if mt.privileged then return true end |