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
%w[href rel target].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.


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

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.


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

def highlighted_text
  @highlighted_text
end

#plain_textObject

Returns the value of attribute plain_text.


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

def plain_text
  @plain_text
end

Class Method Details


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

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

.support?(blob_name) ⇒ Boolean

Returns:

  • (Boolean)

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

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

Instance Method Details

#external_url(name, external_ref) ⇒ Object


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

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

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

def link
  link_dependencies

  highlighted_lines.join.html_safe
end