summaryrefslogtreecommitdiffstats
path: root/acf2/model
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-12-21 00:40:23 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2013-12-21 00:40:44 +0200
commitd6c93b7f19aa7237c020758675c7c6d23cb372a0 (patch)
treeaf1d1e3d9978fc5d20bddc429e0aa87e09633b6f /acf2/model
parente8d8722b08cec9be8c5ee0c0acc7f1e21f7841e3 (diff)
downloadacf2-d6c93b7f19aa7237c020758675c7c6d23cb372a0.tar.bz2
acf2-d6c93b7f19aa7237c020758675c7c6d23cb372a0.tar.xz
model: shortcut for path manipulation functions
Diffstat (limited to 'acf2/model')
-rw-r--r--acf2/model/init.lua20
1 files changed, 11 insertions, 9 deletions
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