From 0b705447b935375dc88c55217ebd2fa656b9fa80 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 23 Nov 2022 13:05:25 +0100 Subject: [PATCH] Simplify hash iteration It's valid to call .sort on a hash and it'll sort by key. This means you don't need to perform an additional lookup when iterating and makes the code more readable. --- templates/mod/ext_filter.conf.erb | 6 ++---- templates/vhost/_directories.erb | 2 +- templates/vhost/_proxy.erb | 4 ++-- templates/vhost/_wsgi.erb | 16 ++++++++-------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/templates/mod/ext_filter.conf.erb b/templates/mod/ext_filter.conf.erb index 67f98fd4c7..620f2bca97 100644 --- a/templates/mod/ext_filter.conf.erb +++ b/templates/mod/ext_filter.conf.erb @@ -1,6 +1,4 @@ # mod_ext_filter definitions -<%- if @ext_filter_define.length >= 1 -%> -<%- @ext_filter_define.keys.sort.each do |name| -%> -ExtFilterDefine <%= name %> <%= @ext_filter_define[name] %> -<%- end -%> +<%- @ext_filter_define.sort.each do |name, value| -%> +ExtFilterDefine <%= name %> <%= value %> <%- end -%> diff --git a/templates/vhost/_directories.erb b/templates/vhost/_directories.erb index 0fbf1da85f..3c890423fb 100644 --- a/templates/vhost/_directories.erb +++ b/templates/vhost/_directories.erb @@ -464,7 +464,7 @@ <%- directory_proxy_pass.flatten.compact.each do |proxy| -%> <%= proxy_pass -%> <%= proxy['url'] -%> <%- if proxy['params'] -%> - <%- proxy['params'].keys.sort.each do |key| -%> <%= key %>=<%= proxy['params'][key] -%> + <%- proxy['params'].sort.each do |key, value| -%> <%= key %>=<%= value -%> <%- end -%> <%- end -%> <%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%> diff --git a/templates/vhost/_proxy.erb b/templates/vhost/_proxy.erb index 5626872c7a..aeb2bb9323 100644 --- a/templates/vhost/_proxy.erb +++ b/templates/vhost/_proxy.erb @@ -19,7 +19,7 @@ <%- end -%> ProxyPass <%= proxy['path'] %> <%= proxy['url'] -%> <%- if proxy['params'] -%> - <%- proxy['params'].keys.sort.each do |key| -%> <%= key %>=<%= proxy['params'][key] -%> + <%- proxy['params'].sort.each do |key, value| -%> <%= key %>=<%= value -%> <%- end -%> <%- end -%> <%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%> @@ -56,7 +56,7 @@ <%- end -%> ProxyPassMatch <%= proxy['path'] %> <%= proxy['url'] -%> <%- if proxy['params'] -%> - <%- proxy['params'].keys.sort.each do |key| -%> <%= key %>=<%= proxy['params'][key] -%> + <%- proxy['params'].sort.each do |key, value| -%> <%= key %>=<%= value -%> <%- end -%> <%- end -%> <%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%> diff --git a/templates/vhost/_wsgi.erb b/templates/vhost/_wsgi.erb index fdc8141700..775ae0fe48 100644 --- a/templates/vhost/_wsgi.erb +++ b/templates/vhost/_wsgi.erb @@ -25,19 +25,19 @@ WSGIProcessGroup <%= @wsgi_process_group %> <% end -%> <% if @wsgi_script_aliases_match and ! @wsgi_script_aliases_match.empty? -%> - <%- @wsgi_script_aliases_match.keys.sort.reverse.each do |key| -%> - <%- if key != '' and @wsgi_script_aliases_match[key] != ''-%> - WSGIScriptAliasMatch <%= key %> "<%= @wsgi_script_aliases_match[key] %>" + <%- @wsgi_script_aliases_match.sort.reverse.each do |key, value| -%> + <%- if key != '' and value != ''-%> + WSGIScriptAliasMatch <%= key %> "<%= value %>" <%- end -%> <%- end -%> <% end -%> <% if @wsgi_script_aliases and ! @wsgi_script_aliases.empty? -%> - <%- @wsgi_script_aliases.keys.sort.reverse.each do |key| -%> - <%- if key != '' and @wsgi_script_aliases[key] != ''-%> - <%- if @wsgi_script_aliases[key].is_a? Array -%> - WSGIScriptAlias <%= key %> <%= @wsgi_script_aliases[key].join(' ') %> + <%- @wsgi_script_aliases.sort.reverse.each do |key, value| -%> + <%- if key != '' and value != ''-%> + <%- if value.is_a? Array -%> + WSGIScriptAlias <%= key %> <%= value.join(' ') %> <%- else -%> - WSGIScriptAlias <%= key %> "<%= @wsgi_script_aliases[key] %>" + WSGIScriptAlias <%= key %> "<%= value %>" <%- end -%> <%- end -%> <%- end -%>