blob: b0ee0877f304a6f2b7f81e9dc339fadc2b69cb7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# frozen_string_literal: true
module Gitlab
class SubmoduleLinks
include Gitlab::Utils::StrongMemoize
def initialize(repository)
@repository = repository
@cache_store = {}
end
def for(submodule, sha)
submodule_url = submodule_url_for(sha, submodule.path)
SubmoduleHelper.submodule_links_for_url(submodule.id, submodule_url, repository)
end
private
attr_reader :repository
def submodule_urls_for(sha)
@cache_store.fetch(sha) do
submodule_urls = repository.submodule_urls_for(sha)
@cache_store[sha] = submodule_urls
end
end
def submodule_url_for(sha, path)
urls = submodule_urls_for(sha)
urls && urls[path]
end
end
end
|