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

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

Constant Summary collapse

PROJECT_PATH_REGEX =
/(?<=["'])[^"']*?\.(?:vb|cs|fs)proj(?=["'])/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(sln_file:) ⇒ SlnProjectPathsFinder

Returns a new instance of SlnProjectPathsFinder.



13
14
15
# File 'lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb', line 13

def initialize(sln_file:)
  @sln_file = sln_file
end

Instance Method Details

#project_pathsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb', line 17

def project_paths
  paths = []
  sln_file_lines = sln_file.content.lines

  sln_file_lines.each_with_index do |line, index|
    next unless line.match?(/^\s*Project/)

    # Don't know how to handle multi-line project declarations yet
    next unless sln_file_lines[index + 1]&.match?(/^\s*EndProject/)

    path = line.split('"')[5]
    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