From 762f688ac0c20b860f39d0cda35d30d69fd6e51d Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Mon, 6 Jan 2025 13:46:41 +0100 Subject: [PATCH] Shorten the conditionals in apt::source Rather than writing: type($release, 'generalized') !~ Type[Array] This uses: $release !~ Array Which is equal, but shorter. It also refactors some conditionals merge some branches which results in shorter code and arguably easier to read. --- manifests/source.pp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/manifests/source.pp b/manifests/source.pp index 70191993f7..5082a89f21 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -288,11 +288,10 @@ fail('cannot create a source entry without specifying a location') } } - if (type($location, 'generalized') !~ Type[Array]) { + if $location !~ Array { warning('For deb822 sources, location must be specified as an array.') $_location = [$location] - } - else { + } else { $_location = $location } @@ -302,30 +301,23 @@ } else { fail('os.distro.codename fact not available: release parameter required') } + } elsif $release !~ Array { + warning("For deb822 sources, 'release' must be specified as an array. Converting to array.") + $_release = [$release] } else { - if (type($release, 'generalized') !~ Type[Array]) { - warning("For deb822 sources, 'release' must be specified as an array. Converting to array.") - $_release = [$release] - } else { - $_release = $release - } + $_release = $release } - if (type($repos, 'generalized') !~ Type[Array]) { + if $repos !~ Array { warning("For deb822 sources, 'repos' must be specified as an array. Converting to array.") $_repos = split($repos, /\s+/) } else { $_repos = $repos } - if $architecture != undef { - if (type($architecture, 'generalized') !~ Type[Array]) { - warning("For deb822 sources, 'architecture' must be specified as an array. Converting to array.") - $_architecture = split($architecture, '[,]') - } - else { - $_architecture = $architecture - } + if $architecture and $architecture !~ Array { + warning("For deb822 sources, 'architecture' must be specified as an array. Converting to array.") + $_architecture = split($architecture, '[,]') } else { $_architecture = $architecture }