Optimized uvl.dependencies
This commit is contained in:
parent
64a4270a59
commit
2d409a3586
1 changed files with 23 additions and 26 deletions
|
@ -14,38 +14,35 @@ $Id$
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
module( "luci.uvl.dependencies", package.seeall )
|
local uvl = require "luci.uvl"
|
||||||
|
local ERR = require "luci.uvl.errors"
|
||||||
|
local util = require "luci.util"
|
||||||
|
local table = require "table"
|
||||||
|
|
||||||
|
local type, unpack = type, unpack
|
||||||
|
local ipairs, pairs = ipairs, pairs
|
||||||
|
|
||||||
|
module "luci.uvl.dependencies"
|
||||||
|
|
||||||
|
|
||||||
local ERR = luci.uvl.errors
|
|
||||||
|
|
||||||
function _parse_reference( r, c, s, o )
|
function _parse_reference( r, c, s, o )
|
||||||
local ref = { }
|
local ref = { }
|
||||||
local vars = {
|
local vars = {
|
||||||
config = ( c or '$config' ),
|
config = c,
|
||||||
section = ( s or '$section' ),
|
section = s,
|
||||||
option = ( o or '$option' )
|
option = o
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, v in ipairs(luci.util.split(r,".")) do
|
for v in r:gmatch("[^.]+") do
|
||||||
table.insert(ref, (v:gsub( "%$(.+)", function(n) return vars[n] end )))
|
ref[#ref+1] = (v:gsub( "%$(.+)", vars ))
|
||||||
end
|
end
|
||||||
|
|
||||||
if c or s then
|
if #ref < 2 then
|
||||||
if #ref == 1 and c and s then
|
table.insert(ref, 1, s or '$section')
|
||||||
ref = { c, s, ref[1] }
|
end
|
||||||
elseif #ref == 2 and c then
|
if #ref < 3 then
|
||||||
ref = { c, unpack(ref) }
|
table.insert(ref, 1, c or '$config')
|
||||||
elseif #ref ~= 3 then
|
|
||||||
ref = nil
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if #ref == 1 then
|
|
||||||
ref = { '$config', '$section', ref[1] }
|
|
||||||
elseif #ref == 2 then
|
|
||||||
ref = { '$config', unpack(ref) }
|
|
||||||
elseif #ref ~= 3 then
|
|
||||||
ref = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return ref
|
return ref
|
||||||
|
@ -54,7 +51,7 @@ end
|
||||||
function _serialize_dependency( dep, v )
|
function _serialize_dependency( dep, v )
|
||||||
local str
|
local str
|
||||||
|
|
||||||
for k, v in luci.util.spairs( dep,
|
for k, v in util.spairs( dep,
|
||||||
function(a,b)
|
function(a,b)
|
||||||
a = ( type(dep[a]) ~= "boolean" and "_" or "" ) .. a
|
a = ( type(dep[a]) ~= "boolean" and "_" or "" ) .. a
|
||||||
b = ( type(dep[b]) ~= "boolean" and "_" or "" ) .. b
|
b = ( type(dep[b]) ~= "boolean" and "_" or "" ) .. b
|
||||||
|
@ -92,7 +89,7 @@ function check( self, object, nodeps )
|
||||||
return false, derr:child(ERR.SME_BADDEP(object,k))
|
return false, derr:child(ERR.SME_BADDEP(object,k))
|
||||||
end
|
end
|
||||||
|
|
||||||
local option = luci.uvl.option( self, object.c, unpack(ref) )
|
local option = uvl.option( self, object.c, unpack(ref) )
|
||||||
|
|
||||||
valid, err = self:_validate_option( option, true )
|
valid, err = self:_validate_option( option, true )
|
||||||
if valid then
|
if valid then
|
||||||
|
|
Loading…
Reference in a new issue