Class: Gitlab::DependencyLinker::Parser::Gemfile

Inherits:
MethodLinker show all
Defined in:
lib/gitlab/dependency_linker/parser/gemfile.rb

Constant Summary collapse

GIT_REGEX =
Gitlab::DependencyLinker::GemfileLinker::GIT_REGEX
GITHUB_REGEX =
Gitlab::DependencyLinker::GemfileLinker::GITHUB_REGEX

Constants inherited from BaseLinker

BaseLinker::GIT_INVALID_URL_REGEX, BaseLinker::REPO_REGEX, BaseLinker::URL_REGEX

Instance Attribute Summary

Attributes inherited from BaseLinker

#highlighted_text, #plain_text

Instance Method Summary collapse

Methods inherited from BaseLinker

#external_url, link, #link, support?

Constructor Details

#initialize(plain_text) ⇒ Gemfile

Returns a new instance of Gemfile.


10
11
12
# File 'lib/gitlab/dependency_linker/parser/gemfile.rb', line 10

def initialize(plain_text)
  @plain_text = plain_text
end

Instance Method Details

#parse(keyword:) ⇒ Object

Returns a list of Gitlab::DependencyLinker::Package

keyword - The package definition keyword, e.g. `:gem` for Gemfile parsing, `:pod` for Podfile.


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gitlab/dependency_linker/parser/gemfile.rb', line 18

def parse(keyword:)
  plain_lines.each_with_object([]) do |line, packages|
    name = fetch(line, method_call_regex(keyword))

    next unless name

    git_ref = fetch(line, GIT_REGEX)
    github_ref = fetch(line, GITHUB_REGEX)

    packages << Gitlab::DependencyLinker::Package.new(name, git_ref, github_ref)
  end
end