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.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/gl_repository/repo_type.rb', line 26

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.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def access_checker_class
  @access_checker_class
end

#container_classObject (readonly)

Returns the value of attribute container_class.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def container_class
  @container_class
end

#guest_read_abilityObject (readonly)

Returns the value of attribute guest_read_ability.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def guest_read_ability
  @guest_read_ability
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def name
  @name
end

#project_resolverObject (readonly)

Returns the value of attribute project_resolver.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def project_resolver
  @project_resolver
end

#repository_resolverObject (readonly)

Returns the value of attribute repository_resolver.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def repository_resolver
  @repository_resolver
end

#suffixObject (readonly)

Returns the value of attribute suffix.



18
19
20
# File 'lib/gitlab/gl_repository/repo_type.rb', line 18

def suffix
  @suffix
end

Instance Method Details

#design?Boolean

Returns:

  • (Boolean)


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

def design?
  name == :design
end

#identifier_for_container(container) ⇒ Object



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

def identifier_for_container(container)
  "#{name}-#{container.id}"
end

#path_suffixObject



63
64
65
# File 'lib/gitlab/gl_repository/repo_type.rb', line 63

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

#project?Boolean

Returns:

  • (Boolean)


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

def project?
  name == :project
end

#project_for(container) ⇒ Object



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

def project_for(container)
  return container unless project_resolver

  project_resolver.call(container)
end

#repository_for(container) ⇒ Object



67
68
69
70
71
72
# File 'lib/gitlab/gl_repository/repo_type.rb', line 67

def repository_for(container)
  check_container(container)
  return unless container

  repository_resolver.call(container)
end

#snippet?Boolean

Returns:

  • (Boolean)


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

def snippet?
  name == :snippet
end

#valid?(repository_path) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
# File 'lib/gitlab/gl_repository/repo_type.rb', line 80

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)


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

def wiki?
  name == :wiki
end