Sha256: 520118568a65fd927b02ececc06eaf543ad79c05ab22a898f8969454b3b796a6

Contents?: true

Size: 851 Bytes

Versions: 117

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

require_dependency "renalware/letters"
require "fileutils"

module Renalware
  module Letters
    # Used for example in a host app like renalware-kch to generate a PDF letter for saving to
    # the electronic public register
    class SavePdfLetterToFileJob < ApplicationJob
      queue_as :pdf_generation
      queue_with_priority 1

      def perform(letter:, file_path:)
        file_path = Pathname(file_path)
        create_folder_if_not_exists(file_path)
        File.open(file_path, "wb") { |file| file << pdf_data_for(letter) }
      end

      def pdf_data_for(letter)
        letter = Renalware::Letters::LetterPresenter.new(letter)
        Renalware::Letters::PdfRenderer.call(letter)
      end

      def create_folder_if_not_exists(path)
        FileUtils.mkdir_p(path.dirname)
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.1.0 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.167 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.166 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.165 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.164 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.163 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.162 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.161 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.160 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.159 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.158 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.157 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.156 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.155 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.153 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.152 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.151 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.149 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb
renalware-core-2.0.148 app/jobs/renalware/letters/save_pdf_letter_to_file_job.rb