Class: Dependabot::Nuget::FileFetcher::SlnProjectPathsFinder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(sln_file:) ⇒ SlnProjectPathsFinder

Returns a new instance of SlnProjectPathsFinder.



16
17
18
# File 'lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb', line 16

def initialize(sln_file:)
  @sln_file = sln_file
end

Instance Method Details

#project_pathsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb', line 21

def project_paths
  paths = T.let([], T::Array[String])
  return paths unless sln_file.content

  sln_file_lines = T.must(sln_file.content).lines

  sln_file_lines.each do |line|
    next unless line.match?(/^\s*Project\(/)
    next unless line.split('"')[5]

    path = line.split('"')[5]
    next unless path

    path = path.tr("\\", "/")

    # If the path doesn't have an extension it's probably a directory
    next unless path.match?(/\.[a-z]{2}proj$/)

    path = File.join(current_dir, path) unless current_dir.nil?
    paths << Pathname.new(path).cleanpath.to_path
  end

  paths
end