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