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

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

Defined Under Namespace

Classes: ValidationFailure

Constant Summary collapse

VERSION_PATTERN =
"
  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
"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



79
80
81
# File 'lib/puppet/util/package/version/pip.rb', line 79

def key
  @key
end

Class Method Details

.compare(version_a, version_b) ⇒ Object



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

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

Raises:



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

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

Raises:



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

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

  compare(key, other.key)
end

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

Returns:

  • (Boolean)


68
69
70
# File 'lib/puppet/util/package/version/pip.rb', line 68

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

#to_sObject Also known as: inspect



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

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