Class: LicenseFinder::Dotnet::AssetFile

Inherits:
Object
  • Object
show all
Defined in:
lib/license_finder/package_managers/dotnet.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ AssetFile

Returns a new instance of AssetFile.



9
10
11
# File 'lib/license_finder/package_managers/dotnet.rb', line 9

def initialize(path)
  @manifest = JSON.parse(File.read(path))
end

Instance Method Details

#dependenciesObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/license_finder/package_managers/dotnet.rb', line 13

def dependencies
  libs = @manifest.fetch('libraries').reject do |_, v|
    v.fetch('type') == 'project'
  end

  libs.keys.map do |name|
    parts = name.split('/')
    PackageMetadata.new(parts[0], parts[1], possible_spec_paths(name))
  end
end

#possible_spec_paths(package_key) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/license_finder/package_managers/dotnet.rb', line 24

def possible_spec_paths(package_key)
  lib = @manifest.fetch('libraries').fetch(package_key)
  spec_filename = lib.fetch('files').find { |f| f.end_with?('.nuspec') }
  return [] if spec_filename.nil?

  @manifest.fetch('packageFolders').keys.map do |root|
    Pathname(root).join(lib.fetch('path'), spec_filename).to_s
  end
end