File: sort_bind.rb

package info (click to toggle)
puppet-module-puppetlabs-haproxy 8.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: ruby: 3,979; sh: 14; makefile: 4
file content (15 lines) | stat: -rw-r--r-- 411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

Puppet::Functions.create_function(:'haproxy::sort_bind') do
  dispatch :sort_bind do
    param 'Hash', :bind
    return_type 'Array'
  end

  def sort_bind(bind)
    bind.sort_by do |address_port|
      md = %r{^((\d+)\.(\d+)\.(\d+)\.(\d+))?(.*)}.match(address_port[0])
      [(md[1] ? md[2..5].reduce(0) { |addr, octet| (addr << 8) + octet.to_i } : -1), md[6]]
    end
  end
end