From 7e2be54276e17da973b987724778649a20f5e50e Mon Sep 17 00:00:00 2001 From: David Lilue <2525462+dvdalilue@users.noreply.github.com> Date: Tue, 27 Jul 2021 15:25:04 +0000 Subject: [PATCH] File registration refactor --- lib/prawn/embedded_files.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/prawn/embedded_files.rb b/lib/prawn/embedded_files.rb index 5e8bd98a1..69cd59d67 100644 --- a/lib/prawn/embedded_files.rb +++ b/lib/prawn/embedded_files.rb @@ -44,14 +44,12 @@ def file(src, options = {}) data = src end - @file_registry ||= {} - file = EmbeddedFile.new(data, mut_opts) - file_obj = @file_registry[file.checksum] + file_obj = file_registry[file.checksum] if file_obj.nil? file_obj = file.build_pdf_object(self) - @file_registry[file.checksum] = file_obj + file_registry[file.checksum] = file_obj end filespec = Filespec.new(file_obj, mut_opts) @@ -63,6 +61,12 @@ def file(src, options = {}) # attach_file(filespec.file_name, filespec_obj) end end + + private + + def file_registry + @file_registry ||= {} + end end end