diff options
Diffstat (limited to 'lib/gitlab/gl_repository/repo_type.rb')
-rw-r--r-- | lib/gitlab/gl_repository/repo_type.rb | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/gitlab/gl_repository/repo_type.rb b/lib/gitlab/gl_repository/repo_type.rb index 6918344aa40..20a0dd48468 100644 --- a/lib/gitlab/gl_repository/repo_type.rb +++ b/lib/gitlab/gl_repository/repo_type.rb @@ -5,16 +5,25 @@ module Gitlab class RepoType attr_reader :name, :access_checker_class, - :repository_accessor + :repository_resolver, + :container_resolver, + :suffix - def initialize(name:, access_checker_class:, repository_accessor:) + def initialize( + name:, + access_checker_class:, + repository_resolver:, + container_resolver: default_container_resolver, + suffix: nil) @name = name @access_checker_class = access_checker_class - @repository_accessor = repository_accessor + @repository_resolver = repository_resolver + @container_resolver = container_resolver + @suffix = suffix end - def identifier_for_repositorable(repositorable) - "#{name}-#{repositorable.id}" + def identifier_for_container(container) + "#{name}-#{container.id}" end def fetch_id(identifier) @@ -22,6 +31,14 @@ module Gitlab match[:id] if match end + def fetch_container!(identifier) + id = fetch_id(identifier) + + raise ArgumentError, "Invalid GL Repository \"#{identifier}\"" unless id + + container_resolver.call(id) + end + def wiki? self == WIKI end @@ -31,11 +48,21 @@ module Gitlab end def path_suffix - project? ? "" : ".#{name}" + suffix ? ".#{suffix}" : '' end - def repository_for(repositorable) - repository_accessor.call(repositorable) + def repository_for(container) + repository_resolver.call(container) + end + + def valid?(repository_path) + repository_path.end_with?(path_suffix) + end + + private + + def default_container_resolver + -> (id) { Project.find_by_id(id) } end end end |