Class: BundleUpdateInteractive::Report
- Inherits:
-
Object
- Object
- BundleUpdateInteractive::Report
- Defined in:
- lib/bundle_update_interactive/report.rb
Instance Attribute Summary collapse
-
#outdated_gems ⇒ Object
readonly
Returns the value of attribute outdated_gems.
Class Method Summary collapse
Instance Method Summary collapse
- #[](gem_name) ⇒ Object
- #bundle_update!(*gem_names) ⇒ Object
- #expand_gems_with_exact_dependencies(*gem_names) ⇒ Object
-
#initialize(gemfile:, current_lockfile:, updated_lockfile:) ⇒ Report
constructor
A new instance of Report.
- #scan_for_vulnerabilities! ⇒ Object
- #updateable_gems ⇒ Object
Constructor Details
#initialize(gemfile:, current_lockfile:, updated_lockfile:) ⇒ Report
Returns a new instance of Report.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bundle_update_interactive/report.rb', line 22 def initialize(gemfile:, current_lockfile:, updated_lockfile:) @current_lockfile = current_lockfile outdated_names = current_lockfile.entries.each_with_object([]) do |current_entry, arr| updated_entry = updated_lockfile[current_entry.name] arr << current_entry.name if current_entry.older_than?(updated_entry) end @outdated_gems ||= outdated_names.sort.each_with_object({}) do |name, hash| hash[name] = OutdatedGem.new( current_lockfile_entry: current_lockfile[name], updated_lockfile_entry: updated_lockfile[name], gemfile_groups: gemfile[name]&.groups ) end.freeze end |
Instance Attribute Details
#outdated_gems ⇒ Object (readonly)
Returns the value of attribute outdated_gems.
20 21 22 |
# File 'lib/bundle_update_interactive/report.rb', line 20 def outdated_gems @outdated_gems end |
Class Method Details
.generate ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/bundle_update_interactive/report.rb', line 11 def generate gemfile = Gemfile.parse current_lockfile = Lockfile.parse updated_lockfile = Lockfile.parse(BundlerCommands.read_updated_lockfile) new(gemfile: gemfile, current_lockfile: current_lockfile, updated_lockfile: updated_lockfile) end |
Instance Method Details
#[](gem_name) ⇒ Object
37 38 39 |
# File 'lib/bundle_update_interactive/report.rb', line 37 def [](gem_name) outdated_gems[gem_name] end |
#bundle_update!(*gem_names) ⇒ Object
63 64 65 66 |
# File 'lib/bundle_update_interactive/report.rb', line 63 def bundle_update!(*gem_names) = (*gem_names) BundlerCommands.update_gems_conservatively(*) end |
#expand_gems_with_exact_dependencies(*gem_names) ⇒ Object
45 46 47 48 |
# File 'lib/bundle_update_interactive/report.rb', line 45 def (*gem_names) gem_names.flatten! gem_names.flat_map { [_1, *outdated_gems[_1].current_lockfile_entry.exact_dependencies] }.uniq end |
#scan_for_vulnerabilities! ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bundle_update_interactive/report.rb', line 50 def scan_for_vulnerabilities! return false if outdated_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)) outdated_gems.each do |name, gem| gem.vulnerable = (vulnerable_gem_names & [name, *current_lockfile[name].exact_dependencies]).any? end true end |
#updateable_gems ⇒ Object
41 42 43 |
# File 'lib/bundle_update_interactive/report.rb', line 41 def updateable_gems outdated_gems.reject { |_, gem| gem.current_lockfile_entry.exact_dependency? } end |