diff options
Diffstat (limited to 'acf/model/combination.lua')
-rw-r--r-- | acf/model/combination.lua | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/acf/model/combination.lua b/acf/model/combination.lua deleted file mode 100644 index 19f84cc..0000000 --- a/acf/model/combination.lua +++ /dev/null @@ -1,50 +0,0 @@ ---[[ -Copyright (c) 2012-2013 Kaarle Ritvanen -See LICENSE file for license details ---]] - -local M = {} - -local err = require('acf.error') -local raise = err.raise - -local fld = require('acf.model.field') -local String = fld.String - -local to_field = require('acf.model.model').to_field - -local object = require('acf.object') -local class = object.class -local super = object.super - - -local stringy = require('stringy') - - -M.Range = class(String) - -function M.Range:init(params) - super(self, M.Range):init(params) - if not self.type then self.type = fld.Integer end -end - -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 - - -M.Union = class(String) - -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 |