Class: Puppet::Util::Package::Version::Debian

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

Defined Under Namespace

Classes: ValidationFailure

Constant Summary collapse

REGEX_EPOCH =

Version string matching regexes

'(?:([0-9]+):)?'
REGEX_UPSTREAM_VERSION =

alphanumerics and the characters . + - ~ , starts with a digit, ~ only of debian_revision is present

'([\.\+~0-9a-zA-Z-]+?)'
REGEX_DEBIAN_REVISION =

alphanumerics and the characters + . ~

'(?:-([\.\+~0-9a-zA-Z]*))?'
REGEX_FULL =
REGEX_EPOCH + REGEX_UPSTREAM_VERSION + REGEX_DEBIAN_REVISION.freeze
REGEX_FULL_RX =
/\A#{REGEX_FULL}\Z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debian_revisionObject (readonly)

Returns the value of attribute debian_revision


55
56
57
# File 'lib/puppet/util/package/version/debian.rb', line 55

def debian_revision
  @debian_revision
end

#epochObject (readonly)

Returns the value of attribute epoch


55
56
57
# File 'lib/puppet/util/package/version/debian.rb', line 55

def epoch
  @epoch
end

#upstream_versionObject (readonly)

Returns the value of attribute upstream_version


55
56
57
# File 'lib/puppet/util/package/version/debian.rb', line 55

def upstream_version
  @upstream_version
end

Class Method Details

.parse(ver) ⇒ Object

Raises:


17
18
19
20
21
22
23
24
25
# File 'lib/puppet/util/package/version/debian.rb', line 17

def self.parse(ver)
  raise ValidationFailure, "Unable to parse '#{ver}' as a string" unless ver.is_a?(String)

  match, epoch, upstream_version, debian_revision = *ver.match(REGEX_FULL_RX)

  raise ValidationFailure, "Unable to parse '#{ver}' as a debian version identifier" unless match

  new(epoch.to_i, upstream_version, debian_revision).freeze
end

Instance Method Details

#<=>(other) ⇒ Object


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/puppet/util/package/version/debian.rb', line 43

def <=>(other)
  return nil unless other.is_a?(self.class)
  cmp = @epoch <=> other.epoch
  if cmp == 0
    cmp = compare_upstream_version(other)
    if cmp == 0
      cmp = compare_debian_revision(other)
    end
  end
  cmp
end

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

Returns:

  • (Boolean)

35
36
37
38
39
40
# File 'lib/puppet/util/package/version/debian.rb', line 35

def eql?(other)
  other.is_a?(self.class) &&
    @epoch.eql?(other.epoch) &&
    @upstream_version.eql?(other.upstream_version) &&
    @debian_revision.eql?(other.debian_revision)
end

#to_sObject Also known as: inspect


27
28
29
30
31
32
# File 'lib/puppet/util/package/version/debian.rb', line 27

def to_s
  s = @upstream_version
  s = "#{@epoch}:#{s}" if @epoch != 0
  s = "#{s}-#{@debian_revision}" if @debian_revision
  s
end