Welcome to mirror list, hosted at ThFree Co, Russian Federation.

repo_type.rb « gl_repository « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7abe6c29a254ef54b74aae464e80ea6f9dc3713e (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
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module Gitlab
  module GlRepository
    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

      def identifier_for_subject(subject)
        "#{name}-#{subject.id}"
      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

      def repository_for(subject)
        repository_accessor.call(subject)
      end
    end
  end
end