Class: Dependabot::DependencyGraphers::Base

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/dependabot/dependency_graphers/base.rb

Direct Known Subclasses

Generic

Constant Summary collapse

PURL_TEMPLATE =
"pkg:%<type>s/%<name>s%<version>s"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_parser:) ⇒ Base

Returns a new instance of Base.



68
69
70
71
72
73
# File 'lib/dependabot/dependency_graphers/base.rb', line 68

def initialize(file_parser:)
  @file_parser = file_parser
  @dependencies = T.let([], T::Array[Dependabot::Dependency])
  @prepared = T.let(false, T::Boolean)
  @errored_fetching_subdependencies = T.let(false, T::Boolean)
end

Instance Attribute Details

#errored_fetching_subdependenciesObject (readonly)

Returns the value of attribute errored_fetching_subdependencies.



60
61
62
# File 'lib/dependabot/dependency_graphers/base.rb', line 60

def errored_fetching_subdependencies
  @errored_fetching_subdependencies
end

#preparedObject (readonly)

Returns the value of attribute prepared.



57
58
59
# File 'lib/dependabot/dependency_graphers/base.rb', line 57

def prepared
  @prepared
end

#subdependency_errorObject (readonly)

Returns the value of attribute subdependency_error.



63
64
65
# File 'lib/dependabot/dependency_graphers/base.rb', line 63

def subdependency_error
  @subdependency_error
end

Instance Method Details

#manifest_group_snapshotsObject



125
126
127
128
129
130
# File 'lib/dependabot/dependency_graphers/base.rb', line 125

def manifest_group_snapshots
  @manifest_group_snapshots ||= T.let(
    build_manifest_group_snapshots,
    T.nilable(T::Array[ManifestGroupSnapshot])
  )
end

#manifest_groupsObject



113
114
115
# File 'lib/dependabot/dependency_graphers/base.rb', line 113

def manifest_groups
  [ManifestGroup.new(primary: relevant_dependency_file, files: dependency_files)]
end

#prepare!Object



86
87
88
89
# File 'lib/dependabot/dependency_graphers/base.rb', line 86

def prepare!
  @dependencies = @file_parser.parse
  @prepared = true
end

#relevant_dependency_fileObject



81
# File 'lib/dependabot/dependency_graphers/base.rb', line 81

def relevant_dependency_file; end

#resolved_dependenciesObject



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/dependabot/dependency_graphers/base.rb', line 92

def resolved_dependencies
  prepare! unless prepared

  @dependencies.each_with_object({}) do |dep, resolved|
    purl = build_purl(dep)
    resolved[purl] = ResolvedDependency.new(
      package_url: purl,
      direct: dep.top_level?,
      runtime: dep.production?,
      dependencies: safe_fetch_subdependencies(dep).map { |d| build_purl(d) }
    )
  end
end