Class: BundleUpdateInteractive::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_update_interactive/report.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_lockfile:, withheld_gems:, updatable_gems:) ⇒ Report

Returns a new instance of Report.



12
13
14
15
16
# File 'lib/bundle_update_interactive/report.rb', line 12

def initialize(current_lockfile:, withheld_gems:, updatable_gems:)
  @current_lockfile = current_lockfile
  @withheld_gems = withheld_gems.freeze
  @updatable_gems = updatable_gems.freeze
end

Instance Attribute Details

#updatable_gemsObject (readonly)

Returns the value of attribute updatable_gems.



10
11
12
# File 'lib/bundle_update_interactive/report.rb', line 10

def updatable_gems
  @updatable_gems
end

#withheld_gemsObject (readonly)

Returns the value of attribute withheld_gems.



10
11
12
# File 'lib/bundle_update_interactive/report.rb', line 10

def withheld_gems
  @withheld_gems
end

Instance Method Details

#all_gemsObject



22
23
24
# File 'lib/bundle_update_interactive/report.rb', line 22

def all_gems
  @all_gems ||= withheld_gems.merge(updatable_gems)
end

#bundle_update!(*gem_names) ⇒ Object



44
45
46
47
# File 'lib/bundle_update_interactive/report.rb', line 44

def bundle_update!(*gem_names)
  expanded_names = expand_gems_with_exact_dependencies(*gem_names)
  BundlerCommands.update_gems_conservatively(*expanded_names)
end

#empty?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bundle_update_interactive/report.rb', line 18

def empty?
  withheld_gems.empty? && updatable_gems.empty?
end

#expand_gems_with_exact_dependencies(*gem_names) ⇒ Object



26
27
28
29
# File 'lib/bundle_update_interactive/report.rb', line 26

def expand_gems_with_exact_dependencies(*gem_names)
  gem_names.flatten!
  gem_names.flat_map { |name| [name, *current_lockfile[name].exact_dependencies] }.uniq
end

#scan_for_vulnerabilities!Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bundle_update_interactive/report.rb', line 31

def scan_for_vulnerabilities!
  return false if all_gems.empty?

  Bundler::Audit::Database.update!(quiet: true)
  audit_report = Bundler::Audit::Scanner.new.report
  vulnerable_gem_names = Set.new(audit_report.vulnerable_gems.map(&:name))

  all_gems.each do |name, gem|
    gem.vulnerable = (vulnerable_gem_names & [name, *current_lockfile[name].exact_dependencies]).any?
  end
  true
end