debian-mirror-gitlab/lib/gitlab/submodule_links.rb

34 lines
736 B
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
module Gitlab
class SubmoduleLinks
include Gitlab::Utils::StrongMemoize
def initialize(repository)
@repository = repository
2019-12-21 20:55:43 +05:30
@cache_store = {}
2019-09-30 21:07:59 +05:30
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)
2019-12-21 20:55:43 +05:30
@cache_store.fetch(sha) do
submodule_urls = repository.submodule_urls_for(sha)
@cache_store[sha] = submodule_urls
2019-09-30 21:07:59 +05:30
end
end
def submodule_url_for(sha, path)
urls = submodule_urls_for(sha)
urls && urls[path]
end
end
end