diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-06-27 20:18:54 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-06-28 13:24:36 +0300 |
commit | 5c960909594d1978f45968f8155ab2afab381298 (patch) | |
tree | 40d6de63ce5818a46b05794a4596329c28d4bd5f /acf/persistence/init.lua | |
parent | 0d5dade5ab61e5cfd3116893aadcb9b16ba5cfb5 (diff) | |
download | acf2-5c960909594d1978f45968f8155ab2afab381298.tar.bz2 acf2-5c960909594d1978f45968f8155ab2afab381298.tar.xz |
eliminate data type arguments from transaction and persistence manager intefaces
utilize model topology information instead
Diffstat (limited to 'acf/persistence/init.lua')
-rw-r--r-- | acf/persistence/init.lua | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/acf/persistence/init.lua b/acf/persistence/init.lua index 3e319c6..80534c2 100644 --- a/acf/persistence/init.lua +++ b/acf/persistence/init.lua @@ -6,6 +6,7 @@ See LICENSE file for license details module(..., package.seeall) local loadmods = require('acf.loader').loadmods +local topology = require('acf.model.root').topology local object = require('acf.object') local pth = require('acf.path') local util = require('acf.util') @@ -31,26 +32,29 @@ function DataStore:split_path(path) return backend, comps end -function DataStore:get(path, t) +function DataStore:get(path) local backend, comps = self:split_path(path) - local res = backend:get(comps, t) + local top = topology(path) - if t ~= nil and res ~= nil then - local atype = type(res) + local res = backend:get(comps, top) - if t == 'table' then assert(atype == 'table') + if top then + local t = top.type + if t and res ~= nil then + local atype = type(res) - else - assert(atype ~= 'table') + if t == 'table' then assert(atype == 'table') - if t == 'string' then res = tostring(res) - elseif t == 'number' then res = tonumber(res) - elseif t == 'boolean' then res = res and true or false - - elseif stringy.startswith(t, 'reference/') then - assert(atype == 'string') + else + assert(atype ~= 'table') - else assert(false) end + if t == 'string' then res = tostring(res) + elseif t == 'number' then res = tonumber(res) + elseif t == 'boolean' then + res = (res and res ~= 'false') and true or false + elseif t == 'reference' then assert(atype == 'string') + else assert(false) end + end end end @@ -61,10 +65,9 @@ function DataStore:_set_multiple(mods) local bms = {} for _, mod in ipairs(mods) do - local path, t, value = unpack(mod) - if not t and value ~= nil then t = type(value) end + local path, value = unpack(mod) local backend, comps = self:split_path(path) - table.insert(util.setdefault(bms, backend, {}), {comps, t, value}) + table.insert(util.setdefault(bms, backend, {}), {comps, value}) end for backend, bm in pairs(bms) do backend:set(bm) end |