File: composite_namevar.rb

package info (click to toggle)
puppet-module-keystone 25.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,428 kB
  • sloc: ruby: 9,684; pascal: 295; python: 38; makefile: 10; sh: 10
file content (45 lines) | stat: -rw-r--r-- 1,104 bytes parent folder | download
1
2
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
34
35
36
37
38
39
40
41
42
43
44
45
require 'puppet_x/keystone/composite_namevar/helpers'

module PuppetX
  module Keystone
    module CompositeNamevar

      class Unset; end

      def self.not_two_colon_regex
        # Anything but 2 consecutive colons.
        Regexp.new(/(?:[^:]|:[^:])+/)
      end

      def self.basic_split_title_patterns(prefix, suffix, separator = '::', *regexps)
        associated_regexps = []
        if regexps.empty? and separator == '::'
          associated_regexps += [not_two_colon_regex, not_two_colon_regex]
        else
          if regexps.count != 2
            raise(Puppet::DevError, 'You must provide two regexps')
          else
            associated_regexps += regexps
          end
        end
        prefix_re = associated_regexps[0]
        suffix_re = associated_regexps[1]
        [
          [
            /^(#{prefix_re})#{separator}(#{suffix_re})$/,
            [
              [prefix],
              [suffix]
            ]
          ],
          [
            /^(#{prefix_re})$/,
            [
              [prefix]
            ]
          ]
        ]
      end
    end
  end
end