From d6c93b7f19aa7237c020758675c7c6d23cb372a0 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Sat, 21 Dec 2013 00:40:23 +0200 Subject: model: shortcut for path manipulation functions --- acf2/model/init.lua | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'acf2/model') diff --git a/acf2/model/init.lua b/acf2/model/init.lua index 5a9a086..31f4dd6 100644 --- a/acf2/model/init.lua +++ b/acf2/model/init.lua @@ -55,7 +55,7 @@ local class = object.class local isinstance = object.isinstance local super = object.super -local pth = require('acf2.path') +M.path = require('acf2.path') local DataStore = require('acf2.persistence') local util = require('acf2.util') @@ -83,7 +83,7 @@ function M.Reference:topology(context) end function M.Reference:abs_scope(context) - return pth.to_absolute(self.scope, node.path(context.parent)) + return M.path.to_absolute(self.scope, node.path(context.parent)) end -- assume one-level refs for now @@ -99,17 +99,19 @@ function M.Reference:_choice(context) if isinstance(v, node.TreeNode) then ch.ref = node.path(v) - if pth.is_subordinate(context.path, ch.ref) then ch = nil end + if M.path.is_subordinate(context.path, ch.ref) then ch = nil end if ch then - ch['ui-value'] = pth.name(ch.ref) - ch.value = self.dereference and ch.ref or pth.escape(ch['ui-value']) + ch['ui-value'] = M.path.name(ch.ref) + ch.value = self.dereference and ch.ref or M.path.escape( + ch['ui-value'] + ) if self.filter then assert(isinstance(v, model.Model)) if not node.match(v, self.filter) then ch.enabled = false end end end - else update(ch, {value=pth.escape(v), ['ui-value']=v}) end + else update(ch, {value=M.path.escape(v), ['ui-value']=v}) end if ch then table.insert(res, ch) end end @@ -125,7 +127,7 @@ function M.Reference:meta(context) end function M.Reference:follow(context, value) - return context.txn:fetch(pth.rawjoin(self:abs_scope(context), value)) + return context.txn:fetch(M.path.rawjoin(self:abs_scope(context), value)) end function M.Reference:load(context, options) @@ -145,7 +147,7 @@ function M.Reference:normalize(context, value) local rel = value - if pth.is_absolute(rel) then + if M.path.is_absolute(rel) then local scope = self:abs_scope(context) local prefix = scope..'/' if not stringy.startswith(rel, prefix) then @@ -155,7 +157,7 @@ function M.Reference:normalize(context, value) end -- assume one-level ref for now - if #pth.split(rel) > 1 then + if #M.path.split(rel) > 1 then raise(path, 'Subtree references not yet supported') end -- cgit v1.2.3