Class: Packages::Go::Module

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/packages/go/module.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(project, name, path) ⇒ Module

Returns a new instance of Module.


10
11
12
13
14
# File 'app/models/packages/go/module.rb', line 10

def initialize(project, name, path)
  @project = project
  @name = name
  @path = path
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


8
9
10
# File 'app/models/packages/go/module.rb', line 8

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path


8
9
10
# File 'app/models/packages/go/module.rb', line 8

def path
  @path
end

#projectObject (readonly)

Returns the value of attribute project


8
9
10
# File 'app/models/packages/go/module.rb', line 8

def project
  @project
end

Instance Method Details

#gomod_valid?(gomod) ⇒ Boolean

Returns:

  • (Boolean)

46
47
48
49
50
51
52
# File 'app/models/packages/go/module.rb', line 46

def gomod_valid?(gomod)
  if Feature.enabled?(:go_proxy_disable_gomod_validation, @project)
    return gomod&.start_with?("module ")
  end

  gomod&.split("\n", 2)&.first == "module #{@name}"
end

#path_valid?(major) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
38
39
40
41
42
43
44
# File 'app/models/packages/go/module.rb', line 35

def path_valid?(major)
  m = /\/v(\d+)$/i.match(@name)

  case major
  when 0, 1
    m.nil?
  else
    !m.nil? && m[1].to_i == major
  end
end

#version_by(ref: nil, commit: nil) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/packages/go/module.rb', line 20

def version_by(ref: nil, commit: nil)
  raise ArgumentError.new 'no filter specified' unless ref || commit
  raise ArgumentError.new 'ref and commit are mutually exclusive' if ref && commit

  if commit
    return version_by_sha(commit) if commit.is_a? String

    return version_by_commit(commit)
  end

  return version_by_name(ref) if ref.is_a? String

  version_by_ref(ref)
end

#versionsObject


16
17
18
# File 'app/models/packages/go/module.rb', line 16

def versions
  strong_memoize(:versions) { Packages::Go::VersionFinder.new(self).execute }
end