Skip to content

Commit 6d15dbe

Browse files
smortexRamesh7
authored andcommitted
Simplify type checking
The typing system allows us to build more straightforward type checking, while here replace some conditional constructs to non-conditional ones as we usualy do nowadays.
1 parent 7c48bce commit 6d15dbe

File tree

7 files changed

+11
-33
lines changed

7 files changed

+11
-33
lines changed

templates/mod/_require.epp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<% if type($requires, 'generalized') == String { -%>
1+
<% if $requires =~ String { -%>
22
<%- if !($requires.downcase in ['', 'unmanaged']) { -%>
33
Require <%= $requires %>
44
<%- } -%>
5-
<% }elsif String(type($requires, 'generalized')).index('Array') == 0 { -%>
5+
<% } elsif $requires =~ Array { -%>
66
<%- $requires.each |$req| { -%>
77
Require <%= $req %>
88
<%- } -%>
9-
<% }elsif String(type($requires, 'generalized')).index('Hash') == 0 { -%>
9+
<% } elsif $requires =~ Hash { -%>
1010
<%- if $requires['enforce'] and $requires['enforce'].downcase in ['all', 'none', 'any'] { -%>
1111
<%- $enforce_str = "Require${requires['enforce'].capitalize}>\n" -%>
1212
<%- $enforce_open = " <${enforce_str}" -%>
@@ -20,7 +20,7 @@
2020
<%- $enforce_close = '' -%>
2121
<%- $indentation = '' -%>
2222
<%- } -%>
23-
<%- if $requires['requires'] and String(type($requires['requires'], 'generalized')).index('Array') == 0 { -%>
23+
<%- if $requires['requires'] and $requires['requires'] =~ Array { -%>
2424
<%# %><%= $enforce_open -%>
2525
<%- $requires['requires'].each |$req| { -%>
2626
<%# %> <%= $indentation -%>Require <%= $req %>

templates/mod/geoip.conf.epp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
GeoIPEnable <%= apache::bool2httpd($enable) %>
22

33
<%- if $db_file and !($db_file in [ false, 'false', '' ]) { -%>
4-
<%- if String(type($db_file, 'generalized')).index('Array') == 0 { -%>
5-
<%- Array($db_file).each |$file| { -%>
4+
<%- [$db_file].flatten.each |$file| { -%>
65
GeoIPDBFile <%= $file %> <%= $flag %>
7-
<%- } -%>
8-
<%- } else { -%>
9-
GeoIPDBFile <%= $db_file %> <%= $flag %>
106
<%- } -%>
117
<%- } -%>
128
GeoIPOutput <%= $output %>

templates/mod/negotiation.conf.epp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
1-
<% if String(type($language_priority, 'generalized')).index('Array') == 0 { -%>
2-
<%- $language_priority_updated = $language_priority.join(' ') -%>
3-
<% } else { -%>
4-
<%- $language_priority_updated = $language_priority -%>
5-
<% } -%>
6-
<% if String(type($force_language_priority, 'generalized')).index('Array') == 0 { -%>
7-
<%- $force_language_priority_updated = $force_language_priority.join(' ') -%>
8-
<% } else { -%>
9-
<%- $force_language_priority_updated = $force_language_priority -%>
10-
<% } -%>
11-
LanguagePriority <%= $language_priority_updated %>
12-
ForceLanguagePriority <%= $force_language_priority_updated %>
1+
LanguagePriority <%= [$language_priority].flatten.join(' ') %>
2+
ForceLanguagePriority <%= [$force_language_priority].flatten.join(' ') %>

templates/mod/pagespeed.conf.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ModPagespeedMessageBufferSize <%= $message_buffer_size %>
7878
SetHandler mod_pagespeed_message
7979
</Location>
8080

81-
<% if String(type($additional_configuration, 'generalized')).index('Array') == 0 { -%>
81+
<% if $additional_configuration =~ Array { -%>
8282
<%= $additional_configuration.join("\n") %>
8383
<% } else { -%>
8484
<% $additional_configuration.each |$key, $value| { -%>

templates/mod/proxy.conf.epp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
<% if $proxy_requests != 'Off' or ( $allow_from and ! $allow_from.empty ) { -%>
1212
<Proxy *>
13-
<%- if String(type($allow_from, 'generalized')).index('Array') == 0 { -%>
14-
Require ip <%= $allow_from.join(" ") %>
15-
<%- } else { -%>
16-
Require ip <%= $allow_from %>
17-
<%- } -%>
13+
Require ip <%= [$allow_from].flatten.join(' ') %>
1814
</Proxy>
1915
<% } -%>
2016

templates/mod/reqtimeout.conf.epp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
<% if type($timeouts, 'generalized') == String { -%>
2-
RequestReadTimeout <%= $timeouts -%>
3-
<% } else { -%>
4-
<%- $timeouts.each |$timeout| { -%>
1+
<%- [$timeouts].flatten.each |$timeout| { -%>
52
RequestReadTimeout <%= $timeout %>
6-
<%- } -%>
73
<% } -%>
84

templates/mod/ssl.conf.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
SSLStaplingReturnResponderErrors <%= apache::bool2httpd($ssl_stapling_return_errors) %>
3434
<%- } -%>
3535
SSLStaplingCache "shmcb:<%= $_stapling_cache %>"
36-
<%- if String(type($ssl_cipher, 'generalized')).index('Hash') == 0 { -%>
36+
<%- if $ssl_cipher =~ Hash { -%>
3737
<%- $ssl_cipher.map |$protocol, $cipher| { -%>
3838
SSLCipherSuite <%= $protocol %> <%= $cipher %>
3939
<%- } -%>

0 commit comments

Comments
 (0)