Class: Gitlab::GlRepository::RepoType

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/gl_repository/repo_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, access_checker_class:, repository_resolver:, container_class: default_container_class, project_resolver: nil, guest_read_ability: :download_code, suffix: nil) ⇒ RepoType

Returns a new instance of RepoType.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/gl_repository/repo_type.rb', line 14

def initialize(
  name:,
  access_checker_class:,
  repository_resolver:,
  container_class: default_container_class,
  project_resolver: nil,
  guest_read_ability: :download_code,
  suffix: nil)
  @name = name
  @access_checker_class = access_checker_class
  @repository_resolver = repository_resolver
  @container_class = container_class
  @project_resolver = project_resolver
  @guest_read_ability = guest_read_ability
  @suffix = suffix
end

Instance Attribute Details

#access_checker_classObject (readonly)

Returns the value of attribute access_checker_class


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def access_checker_class
  @access_checker_class
end

#container_classObject (readonly)

Returns the value of attribute container_class


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def container_class
  @container_class
end

#guest_read_abilityObject (readonly)

Returns the value of attribute guest_read_ability


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def guest_read_ability
  @guest_read_ability
end

#nameObject (readonly)

Returns the value of attribute name


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def name
  @name
end

#project_resolverObject (readonly)

Returns the value of attribute project_resolver


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def project_resolver
  @project_resolver
end

#repository_resolverObject (readonly)

Returns the value of attribute repository_resolver


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def repository_resolver
  @repository_resolver
end

#suffixObject (readonly)

Returns the value of attribute suffix


6
7
8
# File 'lib/gitlab/gl_repository/repo_type.rb', line 6

def suffix
  @suffix
end

Instance Method Details

#design?Boolean

Returns:

  • (Boolean)

51
52
53
# File 'lib/gitlab/gl_repository/repo_type.rb', line 51

def design?
  name == :design
end

#identifier_for_container(container) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/gitlab/gl_repository/repo_type.rb', line 31

def identifier_for_container(container)
  if container.is_a?(Group)
    return "#{container.class.name.underscore}-#{container.id}-#{name}"
  end

  "#{name}-#{container.id}"
end

#path_suffixObject


55
56
57
# File 'lib/gitlab/gl_repository/repo_type.rb', line 55

def path_suffix
  suffix ? ".#{suffix}" : ''
end

#project?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/gitlab/gl_repository/repo_type.rb', line 43

def project?
  name == :project
end

#project_for(container) ⇒ Object


65
66
67
68
69
# File 'lib/gitlab/gl_repository/repo_type.rb', line 65

def project_for(container)
  return container unless project_resolver

  project_resolver.call(container)
end

#repository_for(container) ⇒ Object


59
60
61
62
63
# File 'lib/gitlab/gl_repository/repo_type.rb', line 59

def repository_for(container)
  return unless container

  repository_resolver.call(container)
end

#snippet?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/gitlab/gl_repository/repo_type.rb', line 47

def snippet?
  name == :snippet
end

#valid?(repository_path) ⇒ Boolean

Returns:

  • (Boolean)

71
72
73
74
75
76
77
# File 'lib/gitlab/gl_repository/repo_type.rb', line 71

def valid?(repository_path)
  repository_path.end_with?(path_suffix) &&
  (
    !snippet? ||
    repository_path.match?(Gitlab::PathRegex.full_snippets_repository_path_regex)
  )
end

#wiki?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/gitlab/gl_repository/repo_type.rb', line 39

def wiki?
  name == :wiki
end