Class: Mixlib::Versioning::Format::Rubygems

Inherits:
Mixlib::Versioning::Format show all
Defined in:
lib/mixlib/versioning/format/rubygems.rb

Overview

Handles version strings based on /

SUPPORTED FORMATS


“`text MAJOR.MINOR.PATCH.PRERELEASE MAJOR.MINOR.PATCH.PRERELEASE-ITERATION “`

EXAMPLES


“`text 10.1.1 10.1.1.alpha.1 10.1.1.beta.1 10.1.1.rc.0 10.16.2 “`

Author:

Constant Summary collapse

RUBYGEMS_REGEX =
/^(\d+)\.(\d+)\.(\d+)(?:\.([[:alnum:]]+(?:\.[[:alnum:]]+)?))?(?:\-(\d+))?$/

Instance Attribute Summary

Attributes inherited from Mixlib::Versioning::Format

#build, #input, #iteration, #major, #minor, #patch, #prerelease

Instance Method Summary collapse

Methods inherited from Mixlib::Versioning::Format

#<=>, #build?, #eql?, for, #hash, #in_same_prerelease_line?, #in_same_release_line?, #initialize, #inspect, #prerelease?, #prerelease_build?, #release?, #release_build?, #to_rubygems_string, #to_s, #to_semver_string

Constructor Details

This class inherits a constructor from Mixlib::Versioning::Format

Instance Method Details

#parse(version_string) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/mixlib/versioning/format/rubygems.rb', line 48

def parse(version_string)
  match = version_string.match(RUBYGEMS_REGEX) rescue nil

  unless match
    raise Mixlib::Versioning::ParseError, "'#{version_string}' is not a valid #{self.class} version string!"
  end

  @major, @minor, @patch, @prerelease, @iteration = match[1..5]
  @major, @minor, @patch = [@major, @minor, @patch].map(&:to_i)

  # Do not convert @prerelease or @iteration to an integer;
  # sorting logic will handle the conversion.
  @iteration = if @iteration.nil? || @iteration.empty?
                 nil
               else
                 @iteration.to_i
               end
  @prerelease = nil if @prerelease.nil? || @prerelease.empty?
end