From 96b35ceb0b8e35b39acd7e8a3c30861739eaf01c Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Mon, 17 Mar 2014 18:51:35 +0200 Subject: model: make match a method of Model instances --- aconf/model/init.lua | 2 +- aconf/model/model.lua | 16 ++++++++-------- aconf/model/node.lua | 1 - 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'aconf/model') diff --git a/aconf/model/init.lua b/aconf/model/init.lua index e58d2f0..e3395cc 100644 --- a/aconf/model/init.lua +++ b/aconf/model/init.lua @@ -113,7 +113,7 @@ function M.Reference:_choice(context) ch.value = self.dereference and ch.ref or ch.be_value if self.filter then assert(isinstance(v, model.Model)) - if not node.match(v, self.filter) then ch.enabled = false end + if not v:match(self.filter) then ch.enabled = false end end end diff --git a/aconf/model/model.lua b/aconf/model/model.lua index e1b61bf..747d277 100644 --- a/aconf/model/model.lua +++ b/aconf/model/model.lua @@ -200,16 +200,9 @@ function M.Model:init(context) return map(function(f) return f.name end, mt.meta().fields) end - function mt.match(filter) - for k, v in pairs(filter) do - if not util.contains(v, mt.load(k)) then return false end - end - return true - end - function mt.validate() for _, f in ipairs(_members(Field)) do - if mt.match(f.condition or {}) then f:validate_saved() + if self:match(f.condition or {}) then f:validate_saved() elseif f:_editable() then f:_save() end end if self.validate then self:validate() end @@ -224,5 +217,12 @@ function M.Model:init(context) for _, f in ipairs(_members(Model)) do mt.load(f.name) end end +function M.Model:match(filter) + for k, v in pairs(filter) do + if not util.contains(v, getmetatable(self).load(k)) then return false end + end + return true +end + return M diff --git a/aconf/model/node.lua b/aconf/model/node.lua index 6cca48e..0f9c552 100644 --- a/aconf/model/node.lua +++ b/aconf/model/node.lua @@ -343,7 +343,6 @@ for _, mf in ipairs{ 'contains', 'has_permission', 'insert', - 'match', 'meta', 'mmeta', 'name', -- cgit v1.2.3