Class: Packages::Go::VersionFinder

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Golang
Defined in:
app/finders/packages/go/version_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Golang

#go_path, #local_module_prefix, #package_url, #parse_pseudo_version, #parse_semver, #pkg_go_dev_url, #pseudo_version?, #semver_tag?, #validate_pseudo_version

Constructor Details

#initialize(mod) ⇒ VersionFinder

Returns a new instance of VersionFinder.


10
11
12
# File 'app/finders/packages/go/version_finder.rb', line 10

def initialize(mod)
  @mod = mod
end

Instance Attribute Details

#modObject (readonly)

Returns the value of attribute mod.


8
9
10
# File 'app/finders/packages/go/version_finder.rb', line 8

def mod
  @mod
end

Instance Method Details

#executeObject


14
15
16
17
18
19
# File 'app/finders/packages/go/version_finder.rb', line 14

def execute
  @mod.project.repository.tags
    .filter { |tag| semver_tag? tag }
    .map    { |tag| @mod.version_by(ref: tag) }
    .filter { |ver| ver.valid? }
end

#find(target) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/finders/packages/go/version_finder.rb', line 21

def find(target)
  case target
  when String
    if pseudo_version? target
      semver = parse_semver(target)
      version = parse_pseudo_version(semver)
      commit = validate_pseudo_version(@mod.project, version)
      Packages::Go::ModuleVersion.new(@mod, :pseudo, commit, name: target, semver: semver)
    else
      @mod.version_by(ref: target)
    end

  when Gitlab::Git::Ref
    @mod.version_by(ref: target)

  when ::Commit, Gitlab::Git::Commit
    @mod.version_by(commit: target)

  else
    raise ArgumentError, 'not a valid target'
  end
end