Class: Gitlab::DependencyLinker::BaseLinker

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
lib/gitlab/dependency_linker/base_linker.rb

Constant Summary collapse

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

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.


24
25
26
27
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 24

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


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

def highlighted_text
  @highlighted_text
end

#plain_textObject

Returns the value of attribute plain_text


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

def plain_text
  @plain_text
end

Class Method Details


18
19
20
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 18

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

.support?(blob_name) ⇒ Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 14

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

Instance Method Details

#external_url(name, external_ref) ⇒ Object


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

def external_url(name, external_ref)
  return if external_ref =~ GIT_INVALID_URL_REGEX

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

29
30
31
32
33
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 29

def link
  link_dependencies

  highlighted_lines.join.html_safe
end