Skip to content

Commit

Permalink
Simplify hash iteration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ekohl committed Jan 16, 2023
1 parent 6e4e1e6 commit a15e4b7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
6 changes: 2 additions & 4 deletions templates/mod/ext_filter.conf.erb
Original file line number Diff line number Diff line change
@@ -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 -%>
2 changes: 1 addition & 1 deletion templates/vhost/_directories.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ') -%>
Expand Down
4 changes: 2 additions & 2 deletions templates/vhost/_proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ') -%>
Expand Down Expand Up @@ -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(' ') -%>
Expand Down
16 changes: 8 additions & 8 deletions templates/vhost/_wsgi.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down

0 comments on commit a15e4b7

Please sign in to comment.