Class: Gitlab::DependencyLinker::BaseLinker
- Inherits:
-
Object
- Object
- Gitlab::DependencyLinker::BaseLinker
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- lib/gitlab/dependency_linker/base_linker.rb
Direct Known Subclasses
CargoTomlLinker, GoModLinker, JsonLinker, MethodLinker, RequirementsTxtLinker
Constant Summary collapse
- URL_REGEX =
%r{https?://[^'" ]+}.freeze
- GIT_INVALID_URL_REGEX =
/^git\+#{URL_REGEX}/.freeze
- REPO_REGEX =
%r{[^/'" ]+/[^/'" ]+}.freeze
- VALID_LINK_ATTRIBUTES =
%w[href rel target].freeze
Instance Attribute Summary collapse
-
#highlighted_text ⇒ Object
Returns the value of attribute highlighted_text.
-
#plain_text ⇒ Object
Returns the value of attribute plain_text.
Class Method Summary collapse
Instance Method Summary collapse
- #external_url(name, external_ref) ⇒ Object
-
#initialize(plain_text, highlighted_text) ⇒ BaseLinker
constructor
A new instance of BaseLinker.
- #link ⇒ Object
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_text ⇒ Object
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_text ⇒ Object
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
.link(*args) ⇒ Object
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
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 |
#link ⇒ Object
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 |