Class: SemverDialects::Apk::Version

Inherits:
BaseVersion show all
Defined in:
lib/semver_dialects/apk.rb

Overview

This implementation references the version.c apk-tools implementation gitlab.alpinelinux.org/alpine/apk-tools/-/blob/6052bfef57a81d82451b4cad86f78a2d01959767/src/version.c apk version spec can be found here wiki.alpinelinux.org/wiki/APKBUILD_Reference#pkgver

Constant Summary collapse

PRE_RELEASE_ORDER =
{ 'alpha' => 0, 'beta' => 1, 'pre' => 2, 'rc' => 3 }.freeze
POST_RELEASE_ORDER =
{ 'cvs' => 0, 'svn' => 1, 'git' => 2, 'hg' => 3, 'p' => 4 }.freeze

Instance Attribute Summary collapse

Attributes inherited from BaseVersion

#addition

Instance Method Summary collapse

Methods inherited from BaseVersion

#is_zero?

Constructor Details

#initialize(tokens, pre_release: [], post_release: [], revision: []) ⇒ Version

rubocop:todo Lint/MissingSuper



16
17
18
19
20
21
# File 'lib/semver_dialects/apk.rb', line 16

def initialize(tokens, pre_release: [], post_release: [], revision: []) # rubocop:todo Lint/MissingSuper
  @tokens = tokens
  @pre_release = pre_release
  @post_release = post_release
  @revision = revision
end

Instance Attribute Details

#post_releaseObject (readonly)

Returns the value of attribute post_release.



14
15
16
# File 'lib/semver_dialects/apk.rb', line 14

def post_release
  @post_release
end

#pre_releaseObject (readonly)

Returns the value of attribute pre_release.



14
15
16
# File 'lib/semver_dialects/apk.rb', line 14

def pre_release
  @pre_release
end

#revisionObject (readonly)

Returns the value of attribute revision.



14
15
16
# File 'lib/semver_dialects/apk.rb', line 14

def revision
  @revision
end

#tokensObject (readonly)

Returns the value of attribute tokens.



14
15
16
# File 'lib/semver_dialects/apk.rb', line 14

def tokens
  @tokens
end

Instance Method Details

#<=>(other) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/semver_dialects/apk.rb', line 23

def <=>(other)
  cmp = compare_tokens(tokens, other.tokens)
  return cmp unless cmp.zero?

  cmp = compare_pre_release(pre_release, other.pre_release)
  return cmp unless cmp.zero?

  cmp = compare_post_release(post_release, other.post_release)
  return cmp unless cmp.zero?

  compare_revisions(revision, other.revision)
end

#to_sObject

Note that to_s does not accurately recreate the version string if alphabets are present in the version segment. For instance 1.2.a or 1.2a would both be returned as 1.2.a with to_s More details in gitlab.com/gitlab-org/ruby/gems/semver_dialects/-/merge_requests/97#note_1989192447



40
41
42
43
44
45
46
47
48
# File 'lib/semver_dialects/apk.rb', line 40

def to_s
  @to_s ||= begin
    main = tokens.join('.')
    main += "_#{pre_release.join('')}" unless pre_release.empty?
    main += "_#{post_release.join('')}" unless post_release.empty?
    main += "-#{revision.join('')}" unless revision.empty?
    main
  end
end