diff options
Diffstat (limited to 'acf/model/model.lua')
-rw-r--r-- | acf/model/model.lua | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/acf/model/model.lua b/acf/model/model.lua index 8892221..026ada6 100644 --- a/acf/model/model.lua +++ b/acf/model/model.lua @@ -3,7 +3,7 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local raise = require('acf.error').raise @@ -25,7 +25,7 @@ local util = require('acf.util') local function to_member(obj, params) if not params then params = {} end - if object.issubclass(obj, Model) then + if object.issubclass(obj, M.Model) then params.model = obj return fld.Model(params) end @@ -34,23 +34,23 @@ local function to_member(obj, params) return res end -function to_field(obj, params) +function M.to_field(obj, params) local res = to_member(obj, params) assert(isinstance(res, Field)) return res end -Action = class(Member) +M.Action = class(Member) -function Action:init(params) - super(self, Action):init(params) +function M.Action:init(params) + super(self, M.Action):init(params) if not self.func then error('Function not defined for action') end if self.field then assert(type(self.field) == 'table') - self.field = to_field(self.field) + self.field = M.to_field(self.field) self.field.addr = '/null/action' end @@ -61,15 +61,15 @@ function Action:init(params) end end -function Action:meta(context) - local res = super(self, Action):meta(context) +function M.Action:meta(context) + local res = super(self, M.Action):meta(context) if self.field then res.arg = self.field:meta(context) end return res end -function new(base) - if not base then base = Model end +function M.new(base) + if not base then base = M.Model end local res = class(base) res.members = base == node.TreeNode and {} or util.copy(base.members) @@ -94,15 +94,15 @@ function new(base) setmetatable(res, mt) - if isinstance(base, Model) then util.setdefaults(res, base) end + if isinstance(base, M.Model) then util.setdefaults(res, base) end return res end -Model = new(node.TreeNode) +M.Model = M.new(node.TreeNode) -function Model:init(context) - super(self, Model):init(context) +function M.Model:init(context) + super(self, M.Model):init(context) local mt = getmetatable(self) @@ -146,7 +146,7 @@ function Model:init(context) assert(mt.txn) - if isinstance(v, Action) then + if isinstance(v, M.Action) then local f = v.field and BoundMember(self, k, v.field) if create then return f and f:load(true) end @@ -180,7 +180,7 @@ function Model:init(context) mt.meta.type = 'model' mt.meta.fields = tmeta(Field) - mt.meta.actions = tmeta(Action) + mt.meta.actions = tmeta(M.Action) function mt.members() return util.map(function(f) return f.name end, mt.meta.fields) @@ -198,3 +198,6 @@ function Model:init(context) end end end + + +return M |