Class: Dependabot::Nuget::FileParser::GlobalJsonParser

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/nuget/file_parser/global_json_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(global_json:) ⇒ GlobalJsonParser

Returns a new instance of GlobalJsonParser.


16
17
18
# File 'lib/dependabot/nuget/file_parser/global_json_parser.rb', line 16

def initialize(global_json:)
  @global_json = global_json
end

Instance Method Details

#dependency_setObject

Raises:

  • (Dependabot::DependencyFileNotParseable)

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

def dependency_set
  dependency_set = Dependabot::FileParsers::Base::DependencySet.new

  project_sdks = parsed_global_json.fetch("msbuild-sdks", {})

  raise Dependabot::DependencyFileNotParseable, global_json.path unless project_sdks.is_a?(Hash)

  project_sdks.each do |dependency_name, version|
    dependency_set <<
      Dependency.new(
        name: dependency_name,
        version: version,
        package_manager: "nuget",
        requirements: [{
          requirement: version,
          file: global_json.name,
          groups: [],
          source: nil
        }]
      )
  end

  dependency_set
end