Class: Mixlib::Versioning::Format::SemVer

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

Overview

Handles version strings based on / SemVer 2.0.0-rc.1.

SUPPORTED FORMATS


“`text MAJOR.MINOR.PATCH MAJOR.MINOR.PATCH-PRERELEASE MAJOR.MINOR.PATCH-PRERELEASE+BUILD “`

EXAMPLES


“`text 11.0.0 11.0.0-alpha.1 11.0.0-alpha1+20121218164140 11.0.0-alpha1+20121218164140.git.207.694b062 “`

Author:

Direct Known Subclasses

OpscodeSemVer

Constant Summary collapse

SEMVER_REGEX =
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][a-zA-Z0-9-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/

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
# File 'lib/mixlib/versioning/format/semver.rb', line 48

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

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

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

  @prerelease = nil if @prerelease.nil? || @prerelease.empty?
  @build = nil if @build.nil? || @build.empty?
end