Class: Dependabot::Nuget::FileFetcher::ImportPathsFinder

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

Instance Method Summary collapse

Constructor Details

#initialize(project_file:) ⇒ ImportPathsFinder

Returns a new instance of ImportPathsFinder.



12
13
14
# File 'lib/dependabot/nuget/file_fetcher/import_paths_finder.rb', line 12

def initialize(project_file:)
  @project_file = project_file
end

Instance Method Details

#import_pathsObject



16
17
18
19
20
21
22
23
24
# File 'lib/dependabot/nuget/file_fetcher/import_paths_finder.rb', line 16

def import_paths
  doc = Nokogiri::XML(project_file.content)
  doc.remove_namespaces!
  doc.xpath("/Project/Import").map do |import_node|
    path = import_node.attribute("Project").value.strip.tr("\\", "/")
    path = File.join(current_dir, path) unless current_dir.nil?
    Pathname.new(path).cleanpath.to_path
  end
end

#project_reference_pathsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dependabot/nuget/file_fetcher/import_paths_finder.rb', line 26

def project_reference_paths
  doc = Nokogiri::XML(project_file.content)
  doc.remove_namespaces!
  nodes = doc.xpath("/Project/ItemGroup/ProjectReference").map do |node|
    attribute = node.attribute("Include")
    next unless attribute

    path = attribute.value.strip.tr("\\", "/")
    path = File.join(current_dir, path) unless current_dir.nil?
    Pathname.new(path).cleanpath.to_path
  end

  nodes.compact
end