Class: Dependabot::Nuget::DiscoveryJsonReader

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nuget/discovery/discovery_json_reader.rb

Constant Summary collapse

DISCOVERY_JSON_PATH =
".dependabot/discovery.json"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(discovery_json:) ⇒ DiscoveryJsonReader

Returns a new instance of DiscoveryJsonReader.



39
40
41
# File 'lib/dependabot/nuget/discovery/discovery_json_reader.rb', line 39

def initialize(discovery_json:)
  @discovery_json = discovery_json
end

Class Method Details

.discovery_file_pathObject



22
23
24
# File 'lib/dependabot/nuget/discovery/discovery_json_reader.rb', line 22

def self.discovery_file_path
  File.join(temp_directory, DISCOVERY_JSON_PATH)
end

.discovery_jsonObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/dependabot/nuget/discovery/discovery_json_reader.rb', line 27

def self.discovery_json
  return unless File.exist?(discovery_file_path)

  DependencyFile.new(
    name: Pathname.new(discovery_file_path).cleanpath.to_path,
    directory: temp_directory,
    type: "file",
    content: File.read(discovery_file_path)
  )
end

Instance Method Details

#dependency_setObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dependabot/nuget/discovery/discovery_json_reader.rb', line 44

def dependency_set
  dependency_set = Dependabot::FileParsers::Base::DependencySet.new
  return dependency_set unless workspace_discovery

  workspace_result = T.must(workspace_discovery)
  workspace_result.projects.each do |project|
    dependency_set += project.dependency_set
  end
  if workspace_result.directory_packages_props
    dependency_set += T.must(workspace_result.directory_packages_props).dependency_set
  end
  if workspace_result.dotnet_tools_json
    dependency_set += T.must(workspace_result.dotnet_tools_json).dependency_set
  end
  dependency_set += T.must(workspace_result.global_json).dependency_set if workspace_result.global_json

  dependency_set
end

#workspace_discoveryObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/dependabot/nuget/discovery/discovery_json_reader.rb', line 64

def workspace_discovery
  @workspace_discovery ||= T.let(begin
    return nil unless discovery_json.content

    parsed_json = T.let(JSON.parse(T.must(discovery_json.content)), T::Hash[String, T.untyped])
    WorkspaceDiscovery.from_json(parsed_json)
  end, T.nilable(WorkspaceDiscovery))
rescue JSON::ParserError
  raise Dependabot::DependencyFileNotParseable, discovery_json.path
end