Class: Puppet::Util::Package::Version::Range
- Defined in:
- lib/puppet/util/package/version/range.rb,
lib/puppet/util/package/version/range/eq.rb,
lib/puppet/util/package/version/range/gt.rb,
lib/puppet/util/package/version/range/lt.rb,
lib/puppet/util/package/version/range/gt_eq.rb,
lib/puppet/util/package/version/range/lt_eq.rb,
lib/puppet/util/package/version/range/simple.rb,
lib/puppet/util/package/version/range/min_max.rb
Defined Under Namespace
Classes: Eq, Gt, GtEq, Lt, LtEq, MinMax, Simple, ValidationFailure
Constant Summary collapse
- RANGE_SPLIT =
Parses a version range string into a comparable Puppet::Util::Package::Version::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”`
-
-
/\s+/
- FULL_REGEX =
/\A((?:[<>=])*)(.+)\Z/
Class Method Summary collapse
-
.parse(range_string, version_class) ⇒ Range
A new Range instance.
Class Method Details
.parse(range_string, version_class) ⇒ Range
Returns a new Puppet::Util::Package::Version::Range instance.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppet/util/package/version/range.rb', line 32 def self.parse(range_string, version_class) raise ValidationFailure, "Unable to parse '#{range_string}' as a string" unless range_string.is_a?(String) simples = range_string.split(RANGE_SPLIT).map do |simple| match, operator, version = *simple.match(FULL_REGEX) raise ValidationFailure, "Unable to parse '#{simple}' as a version range identifier" unless match case operator when '>' Gt.new(version_class.parse(version)) when '>=' GtEq.new(version_class.parse(version)) when '<' Lt.new(version_class.parse(version)) when '<=' LtEq.new(version_class.parse(version)) when '' Eq.new(version_class.parse(version)) else raise ValidationFailure, "Operator '#{operator}' is not implemented" end end simples.size == 1 ? simples[0] : MinMax.new(simples[0], simples[1]) end |