class Chelsea::Deps

Project dependencies

Public Class Methods

new(path:, verbose: false) click to toggle source
# File lib/chelsea/deps.rb, line 29
def initialize(path:, verbose: false)
  @verbose = verbose
  ENV['BUNDLE_GEMFILE'] = File.expand_path(path).chomp('.lock')
  @lockfile = Bundler::LockfileParser.new(File.read(path))
end
to_purl(name, version) click to toggle source
# File lib/chelsea/deps.rb, line 39
def self.to_purl(name, version)
  "pkg:gem/#{name}@#{version}"
end

Public Instance Methods

coordinates() click to toggle source

Iterates over all dependencies and stores them in dependencies_versions and coordinates instance vars

# File lib/chelsea/deps.rb, line 72
def coordinates
  dependencies.each_with_object({ 'coordinates' => [] }) do |(name, v), coords|
    coords['coordinates'] << self.class.to_purl(name, v[1])
  end
end
dependencies() click to toggle source

Parses specs from lockfile instanct var and inserts into dependenices instance var

# File lib/chelsea/deps.rb, line 45
def dependencies
  @lockfile.specs.each_with_object({}) do |gem, h|
    h[gem.name] = [gem.name, gem.version]
  end
end
nil?() click to toggle source
# File lib/chelsea/deps.rb, line 35
def nil?
  @dependencies.empty?
end
reverse_dependencies() click to toggle source

Collects all reverse dependencies in reverse_dependencies instance var this rescue block honks

# File lib/chelsea/deps.rb, line 53
def reverse_dependencies # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  reverse = Gem::Commands::DependencyCommand.new
  reverse.options[:reverse_dependencies] = true
  # We want to filter the reverses dependencies by specs in lockfile
  spec_names = @lockfile.specs.map { |i| i.to_s.split }.map do |n, _v|
    n.to_s
  end
  reverse
    .reverse_dependencies(@lockfile.specs)
    .to_h
    .transform_values! do |reverse_dep|
      reverse_dep.select do |name, _dep, _req, _|
        spec_names.include?(name.split('-')[0])
      end
    end
end