diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-09 16:44:04 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-09 16:50:46 +0300 |
commit | 8fb5828d05ba436eff65eb0753ba1dfb1ad1b797 (patch) | |
tree | 3f7c7ecfb3ec864ed867dc2f01c484cd241f9959 /acf/model/init.lua | |
parent | bd7b76e3316959028fc7686357fc916f56a4d10b (diff) | |
download | aconf-8fb5828d05ba436eff65eb0753ba1dfb1ad1b797.tar.bz2 aconf-8fb5828d05ba436eff65eb0753ba1dfb1ad1b797.tar.xz |
basic network configuration module
Diffstat (limited to 'acf/model/init.lua')
-rw-r--r-- | acf/model/init.lua | 94 |
1 files changed, 13 insertions, 81 deletions
diff --git a/acf/model/init.lua b/acf/model/init.lua index f325053..f1f127f 100644 --- a/acf/model/init.lua +++ b/acf/model/init.lua @@ -5,18 +5,28 @@ See LICENSE file for license details module(..., package.seeall) -error = require('acf.error') -local raise = error.raise -local relabel = error.relabel +err = require('acf.error') +local raise = err.raise +local relabel = err.relabel + +local combination = require('acf.model.combination') +Union = combination.Union +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 local model = require('acf.model.model') Action = model.Action 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 @@ -33,84 +43,6 @@ local map = require('acf.util').map require 'stringy' --- TODO object-specific actions - - -local Primitive = class(Field) - -function Primitive:validate(context, value) - local t = self.dtype - if type(value) ~= t then raise(context.path, 'Not a '..t) end -end - - -String = class(Primitive) - -function String:init(params) - super(self, String):init(params) - self.dtype = 'string' -end - -function String:validate(context, value) - super(self, 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) - res['max-length'] = self['max-length'] - return res -end - - -Number = class(Primitive) - -function Number:init(params) - super(self, Number):init(params) - self.dtype = 'number' -end - -function Number:_validate(context, value) - return super(self, Number):_validate( - context, - value and tonumber(value) or value - ) -end - - -Integer = class(Number) - -function Integer:validate(context, value) - super(self, Integer):validate(context, value) - if math.floor(value) ~= value then raise(context.path, 'Not an integer') end -end - - -Boolean = class(Primitive) - -function Boolean:init(params) - super(self, Boolean):init(params) - self.dtype = 'boolean' - self.widget = self.dtype -end - - -Range = class(String) - -function Range:init(params) - super(self, Range):init(params) - if not self.type then self.type = Integer end -end - -function 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 - - Reference = class(Field) function Reference:init(params) |