summaryrefslogtreecommitdiffstats
path: root/aconf/model
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-15 23:23:43 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-25 09:02:57 +0200
commita939dcf652a0287c5c02371216376d06f5507802 (patch)
tree36bf79f5600cd6cb5111851bf458bb8261886cde /aconf/model
parent29f271e0c88a996f4b0d8c65c3812dbb3a91a603 (diff)
downloadaconf-a939dcf652a0287c5c02371216376d06f5507802.tar.bz2
aconf-a939dcf652a0287c5c02371216376d06f5507802.tar.xz
model: params table for TreeNode instances
Diffstat (limited to 'aconf/model')
-rw-r--r--aconf/model/model.lua2
-rw-r--r--aconf/model/node.lua15
-rw-r--r--aconf/model/set.lua4
3 files changed, 12 insertions, 9 deletions
diff --git a/aconf/model/model.lua b/aconf/model/model.lua
index 0ff41d1..4185500 100644
--- a/aconf/model/model.lua
+++ b/aconf/model/model.lua
@@ -108,7 +108,7 @@ end
M.Model = M.new(node.TreeNode)
function M.Model:init(context)
- super(self, M.Model):init(context, 'model', true)
+ super(self, M.Model):init(context, {dtype='model', editable=true})
local mt = getmetatable(self)
diff --git a/aconf/model/node.lua b/aconf/model/node.lua
index 43f06e9..6cca48e 100644
--- a/aconf/model/node.lua
+++ b/aconf/model/node.lua
@@ -16,6 +16,7 @@ local pth = require('aconf.path')
local util = require('aconf.util')
local copy = util.copy
+local setdefaults = util.setdefaults
local update = util.update
@@ -58,7 +59,7 @@ local function equal_tns(tn1, tn2)
return getmetatable(tn1).path == getmetatable(tn2).path
end
-function M.TreeNode:init(context, dtype, editable)
+function M.TreeNode:init(context, params)
local mt = getmetatable(self)
update(mt, context)
@@ -67,7 +68,7 @@ function M.TreeNode:init(context, dtype, editable)
function mt.meta()
if not mt._meta then
- mt._meta = {type=dtype}
+ mt._meta = {type=params.dtype}
if mt.txn then
if mt.parent then
mt._meta['ui-name'] =
@@ -84,7 +85,7 @@ function M.TreeNode:init(context, dtype, editable)
function mt.member_removable(k)
local v = mt.load(k, {dereference=false})
- return editable and (
+ return params.editable and (
not isinstance(v, M.TreeNode) or getmetatable(v).removable()
)
end
@@ -195,9 +196,9 @@ end
M.Collection = class(M.TreeNode)
-function M.Collection:init(context, params, dtype)
+function M.Collection:init(context, params)
super(self, M.Collection):init(
- context, dtype or 'collection', params.editable
+ context, setdefaults(params, {dtype='collection'})
)
self.init = nil
@@ -286,8 +287,8 @@ end
M.List = class(M.Collection)
-function M.List:init(context, params, dtype)
- super(self, M.List):init(context, params, dtype or 'list')
+function M.List:init(context, params)
+ super(self, M.List):init(context, setdefaults(params, {dtype='list'}))
local mt = getmetatable(self)
diff --git a/aconf/model/set.lua b/aconf/model/set.lua
index efed851..9b37ea0 100644
--- a/aconf/model/set.lua
+++ b/aconf/model/set.lua
@@ -18,7 +18,9 @@ function M.Set:init(context, params)
assert(not object.isinstance(params.field, TreeNode))
params.field.dereference = false
- object.super(self, M.Set):init(context, params, 'set')
+ params.dtype = 'set'
+
+ object.super(self, M.Set):init(context, params)
local function find(value)
value = node.BoundMember(