From a939dcf652a0287c5c02371216376d06f5507802 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Sat, 15 Mar 2014 23:23:43 +0200 Subject: model: params table for TreeNode instances --- aconf/model/model.lua | 2 +- aconf/model/node.lua | 15 ++++++++------- aconf/model/set.lua | 4 +++- 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'aconf') 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( -- cgit v1.2.3