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

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)


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

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)


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

def path_valid?(major)
  m = %r{/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

Raises:

  • (ArgumentError)


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

def version_by(ref: nil, commit: nil)
  raise ArgumentError, 'no filter specified' unless ref || commit
  raise ArgumentError, '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
  Packages::Go::VersionFinder.new(self).execute
end