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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bundle_update_interactive/report.rb', line 23 def initialize(gemfile:, current_lockfile:, updated_lockfile:) @current_lockfile = current_lockfile @outdated_gems = current_lockfile.entries.each_with_object({}) do |current_lockfile_entry, hash| name = current_lockfile_entry.name updated_lockfile_entry = updated_lockfile && updated_lockfile[name] next unless current_lockfile_entry.older_than?(updated_lockfile_entry) hash[name] = build_outdated_gem(current_lockfile_entry, updated_lockfile_entry, gemfile[name]&.groups) end.freeze end |
Instance Attribute Details
#outdated_gems ⇒ Object (readonly)
Returns the value of attribute outdated_gems.
21 22 23 |
# File 'lib/bundle_update_interactive/report.rb', line 21 def outdated_gems @outdated_gems end |
Class Method Details
.generate(groups: []) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/bundle_update_interactive/report.rb', line 11 def generate(groups: []) gemfile = Gemfile.parse current_lockfile = Lockfile.parse gems = groups.any? ? current_lockfile.gems_exclusively_installed_by(gemfile: gemfile, groups: groups) : nil updated_lockfile = gems&.none? ? nil : Lockfile.parse(BundlerCommands.read_updated_lockfile(*Array(gems))) new(gemfile: gemfile, current_lockfile: current_lockfile, updated_lockfile: updated_lockfile) end |
Instance Method Details
#[](gem_name) ⇒ Object
34 35 36 |
# File 'lib/bundle_update_interactive/report.rb', line 34 def [](gem_name) outdated_gems[gem_name] end |
#bundle_update!(*gem_names) ⇒ Object
62 63 64 65 |
# File 'lib/bundle_update_interactive/report.rb', line 62 def bundle_update!(*gem_names) = (*gem_names) BundlerCommands.update_gems_conservatively(*) end |
#expand_gems_with_exact_dependencies(*gem_names) ⇒ Object
44 45 46 47 |
# File 'lib/bundle_update_interactive/report.rb', line 44 def (*gem_names) gem_names.flatten! gem_names.flat_map { |name| [name, *current_lockfile[name].exact_dependencies] }.uniq end |
#scan_for_vulnerabilities! ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bundle_update_interactive/report.rb', line 49 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
38 39 40 41 42 |
# File 'lib/bundle_update_interactive/report.rb', line 38 def updateable_gems @updateable_gems ||= outdated_gems.reject do |name, _| current_lockfile[name].exact_requirement? end.freeze end |