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

Inherits:
Object
  • Object
show all
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.



10
11
12
# File 'lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb', line 10

def initialize(sln_file:)
  @sln_file = sln_file
end

Instance Method Details

#project_pathsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dependabot/nuget/file_fetcher/sln_project_paths_finder.rb', line 14

def project_paths
  paths = []
  sln_file_lines = 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]
    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