From 679561c7a472452d4a85ea24d0a07983b7b96ffa Mon Sep 17 00:00:00 2001 From: Jan-Tarek Butt Date: Wed, 24 Apr 2019 00:18:35 +0200 Subject: [PATCH] package/gluon-hoodselector: check_site.lua reduce complexity Signed-off-by: Jan-Tarek Butt --- package/gluon-hoodselector/check_site.lua | 44 +++++++---------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/package/gluon-hoodselector/check_site.lua b/package/gluon-hoodselector/check_site.lua index 6396a67d..281a65d4 100644 --- a/package/gluon-hoodselector/check_site.lua +++ b/package/gluon-hoodselector/check_site.lua @@ -1,35 +1,15 @@ -function need_nil(path) - need(path, function(val) - if val == nil then - return true - end - return false - end, true, "The default domain should not contain shapes") - return nil -end - --Need to check if not default domain and does the default not contain shapes if this_domain() ~= need_string(in_site({'default_domain'})) then - local no_shapes = true - for _,shape in ipairs(need_table(in_domain({'hoodselector', 'shapes'}))) do - no_shapes = false - if #shape >= 2 then - for _, pos in ipairs(shape) do - if pos.lat == nil or not ( pos.lat < 90.0 and pos.lat > -90.0 ) then - need(in_domain({'hoodselector', 'shapes'}), function(err) return false end, true, "lat must match a range +/-90.0") - end - if pos.lon == nil or not ( pos.lon < 180.0 and pos.lon > -180.0 ) then - need(in_domain({'hoodselector', 'shapes'}), function(err) return false end, true, "lon must match a range +/-180.0") - end - end - end - if #shape < 2 then - need(in_domain({'hoodselector', 'shapes'}), function(err) return false end, true, "needs to have at least 2 coordinates for rectangular shapes.") - end - end - if no_shapes then - need(in_domain({'hoodselector', 'shapes'}), function(err) return false end, true, "no shapes are defined in domainss") - end -else -- ente by default domain - need_nil(in_domain({'hoodselector', 'shapes'})) + for _,shape in ipairs(need_table(in_domain({'hoodselector', 'shapes'}))) do + need({'hoodselector', 'shapes'}, function(err) + if #shape >= 2 then + for _, pos in ipairs(shape) do + need({'hoodselector', 'shapes'}, function(err) return pos.lat == nil or not ( pos.lat < 90.0 and pos.lat > -90.0 ) end, false, "lat must match a range +/-90.0") + need({'hoodselector', 'shapes'}, function(err) return pos.lon == nil or not ( pos.lon < 180.0 and pos.lon > -180.0 ) end, false, "lon must match a range +/-180.0") + end + return true + end + return false + end, true, "needs to have at least 2 coordinates for rectangular shapes.") + end end