Puppet Function: :'mediawiki::web::vhost::variant_regex'

Defined in:
modules/mediawiki/lib/puppet/functions/mediawiki/web/vhost/variant_regex.rb
Function type:
Ruby 4.x API

Overview

:'mediawiki::web::vhost::variant_regex'()Object

This function will return a regex to use in apache ProxyPassMatch directives.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'modules/mediawiki/lib/puppet/functions/mediawiki/web/vhost/variant_regex.rb', line 3

Puppet::Functions.create_function(:'mediawiki::web::vhost::variant_regex') do
  dispatch :variant_regex do
    param 'Array[String]', :aliases
    return_type 'String'
  end

  def variant_regex(aliases)
    hierarchy ||= {}
    # first scan all the aliases, organize them hierarchically
    aliases.each  do |al|
      if al.match(/^\w+$/)
        hierarchy[al] ||= []
      elsif match = al.match(/^(\w+)-(\w+)/) # rubocop:disable Lint/AssignmentInCondition
        k, v = match.captures
        hierarchy[k] ||= []
        hierarchy[k] << v
      end
    end
    regexes = []
    hierarchy.each do |prefix, suffixes|
      unless suffixes.empty?
        regexes << "#{prefix}(-(#{suffixes.join('|')}))"
      end
    end
    if regexes.length > 1
      "^/(#{regexes.join('|')})"
    else
      "^/#{regexes[0]}"
    end
  end
end