diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-03-18 19:51:11 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-03-26 15:21:03 +0300 |
commit | d36415b7545fff543f08a5175790e3a92f383475 (patch) | |
tree | b88dfef2992af721191b790ac7a5bc6f1b9eb90b /lib/gitlab/gl_repository | |
parent | d64452ebfc262cfc1324fcaf116e74bc436413d3 (diff) |
Allow multiple repositories per project
This changes the repository type from a binary `wiki?` to a type. So
we can have more than 2 repository types.
Now everywhere we called `.wiki?` and expected a boolean, we check
that type.
Diffstat (limited to 'lib/gitlab/gl_repository')
-rw-r--r-- | lib/gitlab/gl_repository/repo_type.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab/gl_repository/repo_type.rb b/lib/gitlab/gl_repository/repo_type.rb new file mode 100644 index 00000000000..7abe6c29a25 --- /dev/null +++ b/lib/gitlab/gl_repository/repo_type.rb @@ -0,0 +1,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 |