class Puppet::Util::Package::Version::RPM_VERSION_RANGE

Constants

FULL_REGEX
RANGE_SPLIT

Parses a version range string into a comparable {Range} instance.

Currently parsed version range string may take any of the following forms:

  • Regular Version strings

    • ex. `“1.0.0”`, `“1.2.3-pre”`

  • Inequalities

    • ex. `“>1.0.0”`, `“<3.2.0”`, `“>=4.0.0”`

  • Range Intersections (min is always first)

    • ex. `“>1.0.0 <=2.3.0”`

Public Class Methods

parse(range_string, version_class) click to toggle source

@param range_string [String] the version range string to parse @param version_class [Version] a version class implementing comparison operators and parse method @return [Range] a new {Range} instance @api public

   # File lib/puppet/util/package/version/range.rb
31 def self.parse(range_string, version_class)
32   raise ValidationFailure, "Unable to parse '#{range_string}' as a string" unless range_string.is_a?(String)
33   simples = range_string.split(RANGE_SPLIT).map do |simple|
34     match, operator, version = *simple.match(FULL_REGEX)
35     raise ValidationFailure, "Unable to parse '#{simple}' as a version range identifier" unless match
36     case operator
37     when '>'
38       Gt.new(version_class::parse(version))
39     when '>='
40       GtEq.new(version_class::parse(version))
41     when '<'
42       Lt.new(version_class::parse(version))
43     when '<='
44       LtEq.new(version_class::parse(version))
45     when ''
46       Eq.new(version_class::parse(version))
47     else
48       raise ValidationFailure, "Operator '#{operator}' is not implemented"
49     end
50   end
51   simples.size == 1 ? simples[0] : MinMax.new(simples[0], simples[1])
52 end