From e636e3a752f43cc7148fbf15d5575dc4cb1a3693 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 6 Apr 2021 18:00:54 +0200 Subject: [PATCH] add merge_and_update_metadata method --- app/jobs/virus_scanner_job.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/jobs/virus_scanner_job.rb b/app/jobs/virus_scanner_job.rb index 3f612184f..a76ee8979 100644 --- a/app/jobs/virus_scanner_job.rb +++ b/app/jobs/virus_scanner_job.rb @@ -19,7 +19,7 @@ class VirusScannerJob < ApplicationJob scanned_at: Time.zone.now } - blob.update!(metadata: blob.metadata.merge(metadata)) + merge_and_update_metadata(blob, metadata) end def perform(blob) @@ -27,10 +27,16 @@ class VirusScannerJob < ApplicationJob if blob.virus_scanner.done? then return end metadata = extract_metadata_via_virus_scanner(blob) - blob.update!(metadata: blob.metadata.merge(metadata)) + VirusScannerJob.merge_and_update_metadata(blob, metadata) end def extract_metadata_via_virus_scanner(blob) ActiveStorage::VirusScanner.new(blob).metadata end + + private + + def self.merge_and_update_metadata(blob, metadata) + blob.update!(metadata: blob.metadata.merge(metadata)) + end end