Class: Puppet::Util::Package::Version::Pip Private

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/puppet/util/package/version/pip.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: ValidationFailure

Constant Summary collapse

VERSION_PATTERN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"
  v?
  (?:
    (?:(?<epoch>[0-9]+)!)?                              # epoch
    (?<release>[0-9]+(?:\\.[0-9]+)*)                    # release segment
    (?<pre>                                             # pre-release
      [-_\\.]?
      (?<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
      [-_\\.]?
      (?<pre_n>[0-9]+)?
    )?
    (?<post>                                            # post release
      (?:-(?<post_n1>[0-9]+))
      |
      (?:
        [-_\\.]?
        (?<post_l>post|rev|r)
        [-_\\.]?
        (?<post_n2>[0-9]+)?
      )
    )?
    (?<dev>                                             # dev release
      [-_\\.]?
      (?<dev_l>dev)
      [-_\\.]?
      (?<dev_n>[0-9]+)?
    )?
  )
  (?:\\+(?<local>[a-z0-9]+(?:[-_\\.][a-z0-9]+)*))?      # local version
".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


76
77
78
# File 'lib/puppet/util/package/version/pip.rb', line 76

def key
  @key
end

Class Method Details

.compare(version_a, version_b) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


45
46
47
48
49
50
# File 'lib/puppet/util/package/version/pip.rb', line 45

def self.compare(version_a, version_b)
  version_a = parse(version_a) unless version_a.is_a?(self)
  version_b = parse(version_b) unless version_b.is_a?(self)

  version_a <=> version_b
end

.parse(version) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:


36
37
38
39
40
41
42
43
# File 'lib/puppet/util/package/version/pip.rb', line 36

def self.parse(version)
  raise ValidationFailure, version.to_s unless version.is_a? String

  matched = version.match(Regexp.new(("^\\s*") + VERSION_PATTERN + ("\\s*$"), Regexp::EXTENDED | Regexp::MULTILINE | Regexp::IGNORECASE))
  raise ValidationFailure, version unless matched

  new(matched)
end

Instance Method Details

#<=>(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:


71
72
73
74
# File 'lib/puppet/util/package/version/pip.rb', line 71

def <=>(other)
  raise ValidationFailure, other.to_s unless other.is_a?(self.class)
  compare(key, other.key)
end

#eql?(other) ⇒ Boolean Also known as: ==

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

66
67
68
# File 'lib/puppet/util/package/version/pip.rb', line 66

def eql?(other)
  other.is_a?(self.class) && key.eql?(other.key)
end

#to_sObject Also known as: inspect

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/puppet/util/package/version/pip.rb', line 52

def to_s
  parts = []

  parts.push("#{@epoch_data}!")           if @epoch_data && @epoch_data != 0
  parts.push(@release_data.join("."))     if @release_data
  parts.push(@pre_data.join)              if @pre_data
  parts.push(".post#{@post_data[1]}")     if @post_data
  parts.push(".dev#{@dev_data[1]}")       if @dev_data
  parts.push("+#{@local_data.join(".")}") if @local_data

  parts.join
end