Class: SemverDialects::Rpm::Version

Inherits:
BaseVersion show all
Includes:
TokenPairComparison
Defined in:
lib/semver_dialects/rpm.rb

Overview

This implementation references ‘go-rpm-version` github.com/knqyf263/go-rpm-version Which is based on the official `rpmvercmp` github.com/rpm-software-management/rpm/blob/master/rpmio/rpmvercmp.c implementation rpm versioning schema can be found here github.com/rpm-software-management/rpm/blob/master/docs/manual/dependencies.md#versioning Details on how the caret and tilde symbols are handled can be found here docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/#_handling_non_sorting_versions_with_tilde_dot_and_caret

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TokenPairComparison

#compare_token_pair

Methods inherited from BaseVersion

#is_zero?

Constructor Details

#initialize(tokens, epoch: nil, release_tag: nil) ⇒ Version

rubocop:todo Lint/MissingSuper



36
37
38
39
40
# File 'lib/semver_dialects/rpm.rb', line 36

def initialize(tokens, epoch: nil, release_tag: nil) # rubocop:todo Lint/MissingSuper
  @tokens = tokens
  @addition = release_tag
  @epoch = epoch
end

Instance Attribute Details

#additionObject (readonly)

Returns the value of attribute addition.



34
35
36
# File 'lib/semver_dialects/rpm.rb', line 34

def addition
  @addition
end

#epochObject (readonly)

Returns the value of attribute epoch.



34
35
36
# File 'lib/semver_dialects/rpm.rb', line 34

def epoch
  @epoch
end

#tokensObject (readonly)

Returns the value of attribute tokens.



34
35
36
# File 'lib/semver_dialects/rpm.rb', line 34

def tokens
  @tokens
end

Instance Method Details

#<=>(other) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/semver_dialects/rpm.rb', line 42

def <=>(other)
  # Compare epoch first
  epoch_cmp = compare_epochs(epoch, other.epoch)
  return epoch_cmp unless epoch_cmp.zero?

  # Then compare version
  cmp = compare_tokens(tokens, other.tokens)
  return cmp unless cmp.zero?

  # And finally compare release tags
  compare_additions(addition, other.addition)
end

#to_sObject

Note that to_s does not accurately recreate the version string. More details here gitlab.com/gitlab-org/gitlab/-/issues/428941#note_1882343489



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/semver_dialects/rpm.rb', line 57

def to_s
  main = if !epoch.nil?
           "#{epoch}:" + tokens.join('.')
         else
           tokens.join('.')
         end
  main += "-#{addition.tokens.join('.')}" unless addition.nil?

  # Remove . around ~
  main.gsub(/\.~\./, '~')
end