Class: Package::Audit::DuplicatePackageMerger
- Inherits:
-
Object
- Object
- Package::Audit::DuplicatePackageMerger
- Defined in:
- lib/package/audit/services/duplicate_package_merger.rb
Instance Method Summary collapse
-
#initialize(pkgs) ⇒ DuplicatePackageMerger
constructor
A new instance of DuplicatePackageMerger.
-
#run ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(pkgs) ⇒ DuplicatePackageMerger
Returns a new instance of DuplicatePackageMerger.
4 5 6 |
# File 'lib/package/audit/services/duplicate_package_merger.rb', line 4 def initialize(pkgs) @pkgs = pkgs.sort_by(&:full_name) end |
Instance Method Details
#run ⇒ Object
rubocop:disable Metrics/AbcSize
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/package/audit/services/duplicate_package_merger.rb', line 8 def run # rubocop:disable Metrics/AbcSize pkgs = @pkgs.take(1) @pkgs[1..]&.each do |curr| prev = pkgs[-1] if curr.full_name == prev.full_name prev.update(groups: prev.groups | curr.groups, vulnerabilities: prev.vulnerabilities + curr.vulnerabilities, risks: prev.risks + curr.risks) else pkgs << curr end end pkgs end |