Class: Gitlab::DependencyLinker::BaseLinker

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/dependency_linker/base_linker.rb

Constant Summary collapse

URL_REGEX =
%r{https?://[^'" ]+}
GIT_INVALID_URL_REGEX =
/^git\+#{URL_REGEX}/
REPO_REGEX =
%r{[^/'" ]+/[^/'" ]+}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plain_text, highlighted_text) ⇒ BaseLinker

Returns a new instance of BaseLinker.



22
23
24
25
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 22

def initialize(plain_text, highlighted_text)
  @plain_text = plain_text
  @highlighted_text = highlighted_text
end

Instance Attribute Details

#highlighted_textObject

Returns the value of attribute highlighted_text.



20
21
22
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 20

def highlighted_text
  @highlighted_text
end

#plain_textObject

Returns the value of attribute plain_text.



20
21
22
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 20

def plain_text
  @plain_text
end

Class Method Details



16
17
18
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 16

def self.link(...)
  new(...).link
end

.support?(blob_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 12

def self.support?(blob_name)
  Gitlab::FileDetector.type_of(blob_name) == file_type
end

Instance Method Details

#external_url(name, external_ref) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 33

def external_url(name, external_ref)
  return if GIT_INVALID_URL_REGEX.match?(external_ref)

  case external_ref
  when /\A#{URL_REGEX}\z/o
    external_ref
  when /\A#{REPO_REGEX}\z/o
    github_url(external_ref)
  else
    package_url(name)
  end
end


27
28
29
30
31
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 27

def link
  link_dependencies

  highlighted_lines.join.html_safe
end