diff options
Diffstat (limited to 'acf/model')
-rw-r--r-- | acf/model/aaa.lua | 2 | ||||
-rw-r--r-- | acf/model/combination.lua | 21 | ||||
-rw-r--r-- | acf/model/field.lua | 91 | ||||
-rw-r--r-- | acf/model/init.lua | 125 | ||||
-rw-r--r-- | acf/model/model.lua | 37 | ||||
-rw-r--r-- | acf/model/net.lua | 34 | ||||
-rw-r--r-- | acf/model/node.lua | 73 | ||||
-rw-r--r-- | acf/model/permission.lua | 14 | ||||
-rw-r--r-- | acf/model/root.lua | 27 | ||||
-rw-r--r-- | acf/model/set.lua | 11 |
10 files changed, 232 insertions, 203 deletions
diff --git a/acf/model/aaa.lua b/acf/model/aaa.lua index 9e67aa2..d51c10f 100644 --- a/acf/model/aaa.lua +++ b/acf/model/aaa.lua @@ -3,8 +3,6 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) - local M = require('acf.model') Role = M.new() diff --git a/acf/model/combination.lua b/acf/model/combination.lua index 7228233..19f84cc 100644 --- a/acf/model/combination.lua +++ b/acf/model/combination.lua @@ -3,7 +3,7 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local err = require('acf.error') local raise = err.raise @@ -18,30 +18,33 @@ local class = object.class local super = object.super -require 'stringy' +local stringy = require('stringy') -Range = class(String) +M.Range = class(String) -function Range:init(params) - super(self, Range):init(params) +function M.Range:init(params) + super(self, M.Range):init(params) if not self.type then self.type = fld.Integer end end -function Range:validate(context, value) +function M.Range:validate(context, value) local comps = stringy.split(value, '-') if #comps > 2 then raise(context.path, 'Invalid range') end for _, v in ipairs(comps) do to_field(self.type):_validate(context, v) end end -Union = class(String) +M.Union = class(String) -function Union:validate(context, value) - super(self, Union):validate(context, value) +function M.Union:validate(context, value) + super(self, M.Union):validate(context, value) for _, tpe in ipairs(self.types) do local field = to_field(tpe) if err.call(field.validate, field, context, value) then return end end raise(context.path, self.error or 'Invalid value') end + + +return M diff --git a/acf/model/field.lua b/acf/model/field.lua index c69b4d7..d4e934c 100644 --- a/acf/model/field.lua +++ b/acf/model/field.lua @@ -3,7 +3,7 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local err = require('acf.error') local raise = err.raise @@ -22,22 +22,22 @@ local function contains(list, value) return false end -Member = class() +M.Member = class() -function Member:init(params) +function M.Member:init(params) for k, v in pairs(params or {}) do if self[k] == nil then self[k] = v end end end -function Member:auto_ui_name(name) +function M.Member:auto_ui_name(name) if not name then return end return string.gsub( string.upper(string.sub(name, 1, 1))..string.sub(name, 2), '-', ' ' ) end -function Member:meta(context) +function M.Member:meta(context) return { name=self.name, description=self.description, @@ -46,10 +46,10 @@ function Member:meta(context) end -Field = class(Member) +M.Field = class(M.Member) -function Field:init(params) - super(self, Field):init(params) +function M.Field:init(params) + super(self, M.Field):init(params) if self.choice and not self['ui-choice'] then self['ui-choice'] = util.map( @@ -63,9 +63,9 @@ function Field:init(params) end end -function Field:meta(context) +function M.Field:meta(context) assert(self.dtype) - local res = super(self, Field):meta(context) + local res = super(self, M.Field):meta(context) res.type = self.dtype res.required = self.required @@ -77,20 +77,20 @@ function Field:meta(context) return res end -function Field:topology(context) +function M.Field:topology(context) return { {path=context.path, addr=context.addr, type=self.dtype} } end -function Field:load(context) +function M.Field:load(context) if not context.txn then return setmetatable({}, context) end local value = context.txn:get(context.addr) if value == nil then return self.default end return value end -function Field:_validate(context, value) +function M.Field:_validate(context, value) if self.required and value == nil then raise(context.path, 'Required value not set') end @@ -101,18 +101,18 @@ function Field:_validate(context, value) return value end -function Field:validate(context, value) end +function M.Field:validate(context, value) end -function Field:save(context, value) +function M.Field:save(context, value) context.txn:set(context.addr, self:_validate(context, value)) end -function Field:validate_saved(context) +function M.Field:validate_saved(context) self:save(context, self:load(context)) end -local Primitive = class(Field) +local Primitive = class(M.Field) function Primitive:validate(context, value) local t = self.dtype @@ -120,76 +120,76 @@ function Primitive:validate(context, value) end -String = class(Primitive) +M.String = class(Primitive) -function String:init(params) - super(self, String):init(params) +function M.String:init(params) + super(self, M.String):init(params) self.dtype = 'string' end -function String:validate(context, value) - super(self, String):validate(context, value) +function M.String:validate(context, value) + super(self, M.String):validate(context, value) if self['max-length'] and string.len(value) > self['max-length'] then raise(context.path, 'Maximum length exceeded') end end -function String:meta(context) - local res = super(self, String):meta(context) +function M.String:meta(context) + local res = super(self, M.String):meta(context) res['max-length'] = self['max-length'] return res end -Number = class(Primitive) +M.Number = class(Primitive) -function Number:init(params) - super(self, Number):init(params) +function M.Number:init(params) + super(self, M.Number):init(params) self.dtype = 'number' end -function Number:_validate(context, value) - return super(self, Number):_validate( +function M.Number:_validate(context, value) + return super(self, M.Number):_validate( context, value and tonumber(value) or value ) end -Integer = class(Number) +M.Integer = class(M.Number) -function Integer:validate(context, value) - super(self, Integer):validate(context, value) +function M.Integer:validate(context, value) + super(self, M.Integer):validate(context, value) if math.floor(value) ~= value then raise(context.path, 'Not an integer') end end -Boolean = class(Primitive) +M.Boolean = class(Primitive) -function Boolean:init(params) - super(self, Boolean):init(params) +function M.Boolean:init(params) + super(self, M.Boolean):init(params) self.dtype = 'boolean' self.widget = self.dtype end -TreeNode = class(Field) +M.TreeNode = class(M.Field) -function TreeNode:topology(context) - local res = super(self, TreeNode):topology(context) +function M.TreeNode:topology(context) + local res = super(self, M.TreeNode):topology(context) res[1].type = 'table' util.extend(res, node.topology(self:load(context, true))) return res end -function TreeNode:load(context, create) +function M.TreeNode:load(context, create) if context.txn and not ( create or self.create or context.txn:get(context.addr) ) then return end return self.itype(context, self.iparams) end -function TreeNode:save(context, value) +function M.TreeNode:save(context, value) local path = context.path if value == path then return end @@ -216,13 +216,13 @@ function TreeNode:save(context, value) end end -function TreeNode.save_member(node, k, v) node[k] = v end +function M.TreeNode.save_member(node, k, v) node[k] = v end -Model = class(TreeNode) +M.Model = class(M.TreeNode) -function Model:init(params) - super(self, Model):init(params) +function M.Model:init(params) + super(self, M.Model):init(params) assert(self.model) self.itype = self.model @@ -230,3 +230,6 @@ function Model:init(params) self.dtype = 'model' self.widget = self.dtype end + + +return M diff --git a/acf/model/init.lua b/acf/model/init.lua index e1a4dd9..9d09204 100644 --- a/acf/model/init.lua +++ b/acf/model/init.lua @@ -3,34 +3,46 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} -err = require('acf.error') -local raise = err.raise -local relabel = err.relabel +M.error = require('acf.error') +local raise = M.error.raise +local relabel = M.error.relabel local combination = require('acf.model.combination') -Union = combination.Union -Range = combination.Range +M.Union = combination.Union +M.Range = combination.Range local fld = require('acf.model.field') local Field = fld.Field -Boolean = fld.Boolean -Integer = fld.Integer -Number = fld.Number -String = fld.String +M.Boolean = fld.Boolean +M.Integer = fld.Integer +M.Number = fld.Number +M.String = fld.String local model = require('acf.model.model') -Action = model.Action -new = model.new +M.Action = model.Action +M.new = model.new local to_field = model.to_field -net = require('acf.model.net') - -node = require('acf.model.node') -permission = require('acf.model.permission') -register = require('acf.model.root').register -node.Set = require('acf.model.set').Set +M.net = require('acf.model.net') + +local node = require('acf.model.node') +M.node = {} +for _, m in ipairs{ + 'TreeNode', + 'has_permission', + 'insert', + 'meta', + 'mmeta', + 'path', + 'pairs', + 'ipairs' +} do M.node[m] = node[m] end + +M.permission = require('acf.model.permission') +M.register = require('acf.model.root').register +M.node.Set = require('acf.model.set').Set local object = require('acf.object') local class = object.class @@ -40,30 +52,30 @@ local pth = require('acf.path') local map = require('acf.util').map -require 'stringy' +local stringy = require('stringy') -Reference = class(Field) +M.Reference = class(Field) -function Reference:init(params) +function M.Reference:init(params) if not params.widget then params.widget = 'reference' end - super(self, Reference):init(params) + super(self, M.Reference):init(params) self.dtype = 'reference' if not self.scope then self.scope = '/' end end -function Reference:topology(context) - local res = super(self, Reference):topology(context) +function M.Reference:topology(context) + local res = super(self, M.Reference):topology(context) res[1].scope = self.scope return res end -function Reference:abs_scope(context) +function M.Reference:abs_scope(context) return pth.to_absolute(self.scope, node.path(context.parent)) end -function Reference:meta(context) - local res = super(self, Reference):meta(context) +function M.Reference:meta(context) + local res = super(self, M.Reference):meta(context) res.scope = self:abs_scope(context) local txn = context.txn @@ -76,17 +88,17 @@ function Reference:meta(context) return res end -function Reference:follow(context, value) +function M.Reference:follow(context, value) return context.txn:fetch(pth.rawjoin(self:abs_scope(context), value)) end -function Reference:load(context) - local ref = super(self, Reference):load(context) +function M.Reference:load(context) + local ref = super(self, M.Reference):load(context) return (context.txn and ref) and self:follow(context, ref) or ref end -function Reference:_validate(context, value) - super(self, Reference):_validate(context, value) +function M.Reference:_validate(context, value) + super(self, M.Reference):_validate(context, value) if value == nil then return end @@ -114,7 +126,7 @@ function Reference:_validate(context, value) return value end -function Reference:deleted(context, addr) +function M.Reference:deleted(context, addr) local target = self:load(context) if target and node.addr(target) == addr then -- TODO raise error for the target object @@ -123,14 +135,14 @@ function Reference:deleted(context, addr) end -Model = fld.Model +M.Model = fld.Model -Collection = class(fld.TreeNode) +M.Collection = class(fld.TreeNode) -function Collection:init(params, itype) +function M.Collection:init(params, itype) if params.create == nil then params.create = true end - super(self, Collection):init(params) + super(self, M.Collection):init(params) assert(self.type) self.itype = itype or node.Collection @@ -144,45 +156,48 @@ function Collection:init(params, itype) self.widget = self.dtype end -function Collection:auto_ui_name(name) +function M.Collection:auto_ui_name(name) if not name then return end if string.sub(name, -1, -1) ~= 's' then name = name..'s' end - return super(self, Collection):auto_ui_name(name) + return super(self, M.Collection):auto_ui_name(name) end -function Collection:load(context, create) +function M.Collection:load(context, create) if not self.iparams.field then self.iparams.field = to_field(self.type) end - return super(self, Collection):load(context, create) + return super(self, M.Collection):load(context, create) end -List = class(Collection) -function List:init(params) super(self, List):init(params, node.List) end +M.List = class(M.Collection) +function M.List:init(params) super(self, M.List):init(params, node.List) end -Set = class(Collection) -function Set:init(params) super(self, Set):init(params, node.Set) end -function Set.save_member(tn, k, v) node.insert(tn, v) end +M.Set = class(M.Collection) +function M.Set:init(params) super(self, M.Set):init(params, M.node.Set) end +function M.Set.save_member(tn, k, v) node.insert(tn, v) end -- experimental -Mixed = class(Collection) +M.Mixed = class(M.Collection) -function Mixed:init(params) - params.type = Mixed - super(self, Mixed):init(params, node.Mixed) +function M.Mixed:init(params) + params.type = M.Mixed + super(self, M.Mixed):init(params, node.Mixed) self.pfield = Field() end -function Mixed:topology(context) return {} end +function M.Mixed:topology(context) return {} end -function Mixed:load(context) +function M.Mixed:load(context) local value = self.pfield:load(context) - if type(value) == 'table' then return super(self, Mixed):load(context) end + if type(value) == 'table' then return super(self, M.Mixed):load(context) end return value end -function Mixed:save(context, value) - if type(value) == 'table' then super(self, Mixed):save(context, value) +function M.Mixed:save(context, value) + if type(value) == 'table' then super(self, M.Mixed):save(context, value) else self.pfield:save(context, value) end end + + +return M 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 diff --git a/acf/model/net.lua b/acf/model/net.lua index dc63e75..e5c1836 100644 --- a/acf/model/net.lua +++ b/acf/model/net.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 local Union = require('acf.model.combination').Union @@ -18,13 +18,13 @@ local super = object.super local update = require('acf.util').update -require 'stringy' +local stringy = require('stringy') -IPv4Address = class(String) +M.IPv4Address = class(String) -function IPv4Address:validate(context, value) - super(self, IPv4Address):validate(context, value) +function M.IPv4Address:validate(context, value) + super(self, M.IPv4Address):validate(context, value) local function test(...) if #{...} ~= 4 then return true end for _, octet in ipairs{...} do @@ -37,10 +37,10 @@ function IPv4Address:validate(context, value) end -IPv6Address = class(String) +M.IPv6Address = class(String) -function IPv6Address:validate(context, value) - super(self, IPv6Address):validate(context, value) +function M.IPv6Address:validate(context, value) + super(self, M.IPv6Address):validate(context, value) local function invalid() raise(context.path, 'Invalid IPv6 address') end @@ -73,20 +73,24 @@ function IPv6Address:validate(context, value) end -IPAddress = class(Union) +M.IPAddress = class(Union) -function IPAddress:init(params) - super(self, IPAddress):init( +function M.IPAddress:init(params) + super(self, M.IPAddress):init( update( - params, {types={IPv4Address, IPv6Address}, error='Invalid IP address'} + params, + {types={M.IPv4Address, M.IPv6Address}, error='Invalid IP address'} ) ) end -Port = class(fld.Integer) +M.Port = class(fld.Integer) -function Port:validate(context, value) - super(self, Port):validate(context, value) +function M.Port:validate(context, value) + super(self, M.Port):validate(context, value) if value < 0 or value > 65535 then raise(context.path, 'Invalid port') end end + + +return M diff --git a/acf/model/node.lua b/acf/model/node.lua index 688336c..b708112 100644 --- a/acf/model/node.lua +++ b/acf/model/node.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 @@ -16,9 +16,9 @@ local pth = require('acf.path') local util = require('acf.util') -BoundMember = class() +M.BoundMember = class() -function BoundMember:init(parent, name, field) +function M.BoundMember:init(parent, name, field) local pmt = getmetatable(parent) local mt = {} @@ -45,9 +45,9 @@ function BoundMember:init(parent, name, field) end -TreeNode = class() +M.TreeNode = class() -function TreeNode:init(context) +function M.TreeNode:init(context) local mt = getmetatable(self) util.update(mt, context) @@ -75,13 +75,13 @@ function TreeNode:init(context) if ({create=true, delete=true})[permission] then permission = 'modify' end - return has_permission(mt.parent, user, permission) + return M.has_permission(mt.parent, user, permission) end mt.txn.validable[mt.path] = mt.addr end -function TreeNode:fetch(path, create) +function M.TreeNode:fetch(path, create) if type(path) == 'string' then path = pth.split(path) end if #path == 0 then return self end @@ -102,10 +102,10 @@ function TreeNode:fetch(path, create) raise(pth.join(mt.path, name), 'Is a primitive value') end - return TreeNode.fetch(next, path, create) + return M.TreeNode.fetch(next, path, create) end -function TreeNode:search_refs(path) +function M.TreeNode:search_refs(path) if type(path) == 'string' then path = pth.split(path) end if #path == 0 then return {} end @@ -121,7 +121,7 @@ function TreeNode:search_refs(path) local member = mt.member(name) if member.deleted then return {member} end - return isinstance(next, TreeNode) and TreeNode.search_refs( + return isinstance(next, M.TreeNode) and M.TreeNode.search_refs( next, path ) or {} end @@ -138,22 +138,22 @@ function TreeNode:search_refs(path) end -Collection = class(TreeNode) +M.Collection = class(M.TreeNode) -function Collection:init(context, params) - super(self, Collection):init(context) +function M.Collection:init(context, params) + super(self, M.Collection):init(context) self.init = nil self.fetch = nil self.search_refs = nil local mt = getmetatable(self) - local field = BoundMember(self, pth.wildcard, params.field) + local field = M.BoundMember(self, pth.wildcard, params.field) function mt.topology() return field:topology() end function mt.member(name) - return BoundMember(self, name, params.field) + return M.BoundMember(self, name, params.field) end function mt.load(k, create) return mt.member(k):load(create) end @@ -189,10 +189,10 @@ function Collection:init(context, params) end -List = class(Collection) +M.List = class(M.Collection) -function List:init(context, params) - super(self, List):init(context, params) +function M.List:init(context, params) + super(self, M.List):init(context, params) local mt = getmetatable(self) mt.meta.type = 'list' @@ -220,10 +220,10 @@ end -- experimental -Mixed = class(Collection) +M.Mixed = class(M.Collection) -function Mixed:init(context, params) - super(self, Mixed):init(context, params) +function M.Mixed:init(context, params) + super(self, M.Mixed):init(context, params) -- TODO dynamic meta: list non-leaf children local mt = getmetatable(self) @@ -242,27 +242,17 @@ local function meta_func(attr) end end -addr = meta_func('addr') -has_permission = meta_func('has_permission') -insert = meta_func('insert') -members = meta_func('members') -meta = meta_func('meta') -mmeta = meta_func('mmeta') -parent = meta_func('parent') -path = meta_func('path') -topology = meta_func('topology') -validate = meta_func('validate') +for _, mf in ipairs{ + 'addr', 'has_permission', 'insert', 'meta', 'mmeta', 'path', 'topology' +} do M[mf] = meta_func(mf) end -local rawpairs = pairs -local rawipairs = ipairs - -function pairs(tbl) - if not isinstance(tbl, TreeNode) then return rawpairs(tbl) end +function M.pairs(tbl) + if not isinstance(tbl, M.TreeNode) then return pairs(tbl) end local mt = getmetatable(tbl) local res = {} - for _, member in rawipairs(mt.members()) do res[member] = mt.load(member) end - return rawpairs(res) + for _, member in ipairs(mt.members()) do res[member] = mt.load(member) end + return pairs(res) end local function _ipairs(mt, i) @@ -271,7 +261,10 @@ local function _ipairs(mt, i) if v == nil then return end return i, v end -function ipairs(tbl) - if not isinstance(tbl, TreeNode) then return rawipairs(tbl) end +function M.ipairs(tbl) + if not isinstance(tbl, M.TreeNode) then return ipairs(tbl) end return _ipairs, getmetatable(tbl), 0 end + + +return M diff --git a/acf/model/permission.lua b/acf/model/permission.lua index 94b3df0..271d478 100644 --- a/acf/model/permission.lua +++ b/acf/model/permission.lua @@ -3,16 +3,20 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local insert = require('acf.model.node').insert -local start = require('acf.transaction').start +local start_txn = require('acf.transaction') -function define(path, ...) - local txn = start() +function M.define(path, ...) + local txn = start_txn() local db = txn:fetch('/auth/permissions') for _, permission in ipairs{...} do insert(db, permission..path) end txn:commit() end -function defaults(path) define(path, 'read', 'create', 'modify', 'delete') end +function M.defaults(path) + M.define(path, 'read', 'create', 'modify', 'delete') +end + +return M diff --git a/acf/model/root.lua b/acf/model/root.lua index a793c75..17c5cfb 100644 --- a/acf/model/root.lua +++ b/acf/model/root.lua @@ -3,7 +3,7 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local model = require('acf.model.model') local node = require('acf.model.node') @@ -14,17 +14,17 @@ local util = require('acf.util') local setdefault = util.setdefault -RootModel = model.new() +M.RootModel = model.new() -function RootModel:init(txn) - object.super(self, RootModel):init{txn=txn, path='/', addr='/null/root'} +function M.RootModel:init(txn) + object.super(self, M.RootModel):init{txn=txn, path='/', addr='/null/root'} end -function RootModel:has_permission(user, permission) +function M.RootModel:has_permission(user, permission) return permission == 'read' end -function RootModel:meta(path) +function M.RootModel:meta(path) local obj = self:fetch(path, true) if object.isinstance(obj, node.TreeNode) then return node.meta(obj) end return node.mmeta(self:fetch(pth.parent(path), true), pth.name(path)) @@ -34,7 +34,7 @@ end local _topology = {} local order = 0 -function topology(addr, create) +function M.topology(addr, create) local top = _topology if type(addr) == 'table' then addr = util.copy(addr) else addr = pth.split(addr) end @@ -56,15 +56,15 @@ function topology(addr, create) return defaults(top) end -function register(name, field, params) +function M.register(name, field, params) if not params then params = {} end params.create = true - RootModel[name] = model.to_field(field, params) + M.RootModel[name] = model.to_field(field, params) - local root = RootModel() + local root = M.RootModel() for _, record in ipairs(node.topology(root:fetch(name))) do - local top = topology(record.addr, true) + local top = M.topology(record.addr, true) setdefault(top, 'order', order) order = order + 1 @@ -82,7 +82,10 @@ function register(name, field, params) root:fetch(pth.to_absolute(record.scope, pth.parent(record.path))) ) set('scope', scope) - table.insert(topology(scope, true).referrers, record.path) + table.insert(M.topology(scope, true).referrers, record.path) end end end + + +return M diff --git a/acf/model/set.lua b/acf/model/set.lua index 47eeaa8..695d7cb 100644 --- a/acf/model/set.lua +++ b/acf/model/set.lua @@ -3,18 +3,18 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local TreeNode = require('acf.model.field').TreeNode local npairs = require('acf.model.node').pairs local object = require('acf.object') -Set = object.class(require('acf.model.node').List) +M.Set = object.class(require('acf.model.node').List) -function Set:init(context, params) +function M.Set:init(context, params) assert(not object.isinstance(params.field, TreeNode)) - object.super(self, Set):init(context, params) + object.super(self, M.Set):init(context, params) local function find(value) for i, member in npairs(self) do @@ -37,3 +37,6 @@ function Set:init(context, params) local insert = mt.insert function mt.insert(v) if not find(v) then insert(v) end end end + + +return M |