2019-03-18 16:51:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
2019-04-30 09:37:07 +00:00
|
|
|
class GlRepository
|
2019-03-18 16:51:11 +00:00
|
|
|
class RepoType
|
|
|
|
attr_reader :name,
|
|
|
|
:access_checker_class,
|
|
|
|
:repository_accessor
|
|
|
|
|
|
|
|
def initialize(name:, access_checker_class:, repository_accessor:)
|
|
|
|
@name = name
|
|
|
|
@access_checker_class = access_checker_class
|
|
|
|
@repository_accessor = repository_accessor
|
|
|
|
end
|
|
|
|
|
2020-01-20 12:09:02 +00:00
|
|
|
def identifier_for_repositorable(repositorable)
|
|
|
|
"#{name}-#{repositorable.id}"
|
2019-03-18 16:51:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def fetch_id(identifier)
|
|
|
|
match = /\A#{name}-(?<id>\d+)\z/.match(identifier)
|
|
|
|
match[:id] if match
|
|
|
|
end
|
|
|
|
|
|
|
|
def wiki?
|
|
|
|
self == WIKI
|
|
|
|
end
|
|
|
|
|
|
|
|
def project?
|
|
|
|
self == PROJECT
|
|
|
|
end
|
|
|
|
|
|
|
|
def path_suffix
|
|
|
|
project? ? "" : ".#{name}"
|
|
|
|
end
|
|
|
|
|
2020-01-20 12:09:02 +00:00
|
|
|
def repository_for(repositorable)
|
|
|
|
repository_accessor.call(repositorable)
|
2019-03-18 16:51:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-24 21:06:18 +00:00
|
|
|
|
|
|
|
Gitlab::GlRepository::RepoType.prepend_if_ee('EE::Gitlab::GlRepository::RepoType')
|