File: util.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 (25 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (5)
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
module Util
  # Splits the rightmost part of a string using '::' as delimiter
  # Returns an array of both parts or nil if either is empty.
  # An empty rightmost part is ignored and converted as 'string::' => 'string'
  #
  # Examples:
  # "foo"             -> ["foo", nil]
  # "foo::"           -> ["foo", nil]
  # "foo::bar"        -> ["foo", "bar"]
  # "foo::bar::"      -> ["foo", "bar"]
  # "::foo"           -> [nil, "foo"]
  # "::foo::"         -> [nil, "foo"]
  # "foo::bar::baz"   -> ["foo::bar", "baz"]
  # "foo::bar::baz::" -> ["foo::bar", "baz"]
  #
  def self.split_domain(str)
    left, right = nil, nil
    unless str.nil?
      left, delimiter, right = str.gsub(/::$/, '').rpartition('::')
      left, right = right, nil if delimiter.empty?
      left = nil if left.empty?
    end
    return [left, right]
  end
end