diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-01 09:25:44 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-05-01 14:10:59 +0300 |
commit | 0cd6597bec4f1b5c727cedcefe40085c6aa43c3b (patch) | |
tree | 37560799b03180436aafa8a72d86b94c7345d027 /acf/persistence/backends | |
parent | 13eb04abbc9d8561e44786ce9b0dd94bc1454e1f (diff) | |
download | aconf-0cd6597bec4f1b5c727cedcefe40085c6aa43c3b.tar.bz2 aconf-0cd6597bec4f1b5c727cedcefe40085c6aa43c3b.tar.xz |
make persistence manager aware of data types
coerce values into proper types
Diffstat (limited to 'acf/persistence/backends')
-rw-r--r-- | acf/persistence/backends/augeas.lua | 2 | ||||
-rw-r--r-- | acf/persistence/backends/files.lua | 4 | ||||
-rw-r--r-- | acf/persistence/backends/json.lua | 4 | ||||
-rw-r--r-- | acf/persistence/backends/null.lua | 2 | ||||
-rw-r--r-- | acf/persistence/backends/volatile.lua | 2 |
5 files changed, 7 insertions, 7 deletions
diff --git a/acf/persistence/backends/augeas.lua b/acf/persistence/backends/augeas.lua index cf4614f..c33e09a 100644 --- a/acf/persistence/backends/augeas.lua +++ b/acf/persistence/backends/augeas.lua @@ -12,7 +12,7 @@ backend = require('acf.object').class() function backend:init() self.aug = require('augeas').init() end -function backend:get(path) +function backend:get(path, tpe) path = '/'..pth.mjoin(unpack(path)) local _, count = self.aug:match(path) if count == 0 then return end diff --git a/acf/persistence/backends/files.lua b/acf/persistence/backends/files.lua index 31058a7..03eadff 100644 --- a/acf/persistence/backends/files.lua +++ b/acf/persistence/backends/files.lua @@ -16,7 +16,7 @@ backend = require('acf.object').class() -- TODO cache expiration function backend:init() self.cache = {} end -function backend:get(path) +function backend:get(path, tpe) local name = pth.mjoin('/', unpack(path)) if not self.cache[name] then @@ -59,7 +59,7 @@ function backend:set(mods) else local file = util.open_file(name, 'w') - file:write(value) + file:write(tostring(value)) file:close() self.cache[name] = value diff --git a/acf/persistence/backends/json.lua b/acf/persistence/backends/json.lua index 1ac977e..57352d8 100644 --- a/acf/persistence/backends/json.lua +++ b/acf/persistence/backends/json.lua @@ -51,12 +51,12 @@ function backend:split_path(path) end end -function backend:get(path) +function backend:get(path, tpe) local fpath, jpath = self:split_path(path) if not self.cache[fpath] then self.cache[fpath] = Cache(json.decode(util.read_file(fpath))) end - return self.cache[fpath]:get(jpath) + return self.cache[fpath]:get(jpath, tpe) end function backend:set(mods) diff --git a/acf/persistence/backends/null.lua b/acf/persistence/backends/null.lua index 62a793f..45b6f22 100644 --- a/acf/persistence/backends/null.lua +++ b/acf/persistence/backends/null.lua @@ -6,5 +6,5 @@ See LICENSE file for license details module(..., package.seeall) backend = require('acf.object').class() -function backend:get(path) if #path == 0 then return {} end end +function backend:get(path, tpe) if #path == 0 then return {} end end function backend:set(mods) end diff --git a/acf/persistence/backends/volatile.lua b/acf/persistence/backends/volatile.lua index 63d7265..165e7fc 100644 --- a/acf/persistence/backends/volatile.lua +++ b/acf/persistence/backends/volatile.lua @@ -29,7 +29,7 @@ function backend:_get(path) return res end -function backend:get(path) +function backend:get(path, tpe) local res = self:_get(path) return type(res) == 'table' and keys(res) or res end |