Class: Gitlab::DependencyLinker::BaseLinker
- Inherits:
-
Object
- Object
- Gitlab::DependencyLinker::BaseLinker
- Defined in:
- lib/gitlab/dependency_linker/base_linker.rb
Direct Known Subclasses
CargoTomlLinker, GoModLinker, JsonLinker, MethodLinker, RequirementsTxtLinker
Constant Summary collapse
- URL_REGEX =
%r{https?://[^'" ]+}
- GIT_INVALID_URL_REGEX =
/^git\+#{URL_REGEX}/
- REPO_REGEX =
%r{[^/'" ]+/[^/'" ]+}
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.
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_text ⇒ Object
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_text ⇒ Object
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
.link ⇒ Object
16 17 18 |
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 16 def self.link(...) new(...).link end |
.support?(blob_name) ⇒ 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 45 46 |
# File 'lib/gitlab/dependency_linker/base_linker.rb', line 33 def external_url(name, external_ref) ref = external_ref.to_s return if GIT_INVALID_URL_REGEX.match?(ref) case ref when /\A#{URL_REGEX}\z/o ref when /\A#{REPO_REGEX}\z/o github_url(ref) else package_url(name) end end |
#link ⇒ Object
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 |