File: sort_by_version.rb

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

# A function that sorts an array of version numbers.
Puppet::Functions.create_function(:'extlib::sort_by_version') do
  # @param versions An array of version strings you want sorted.
  # @return Returns the sorted array.
  # @example Calling the function
  #   extlib::sort_by_version(['10.0.0b12', '10.0.0b3', '10.0.0a2', '9.0.10', '9.0.3'])
  dispatch :sort_by_version do
    param 'Array[String]', :versions
    return_type 'Array[String]'
  end

  def sort_by_version(versions)
    versions.sort_by { |v| Gem::Version.new(v) }
  end
end