Sha256: 371f34284129820aa32c0c3fce97cf7423ab1e42fb2a9c34667d6a7579b60720
Contents?: true
Size: 1.02 KB
Versions: 16
Compression:
Stored size: 1.02 KB
Contents
class Dorsale::BillingMachine::PdfFileGenerator < Dorsale::Service attr_reader :document def initialize(document) # I have no idea why I need to do that, # if I don't do that, CarrierWare do not stores the file. # The reload() method don't work either. # The problem appears only on server, not in console. # I think CarrierWave do not work anymore after first save. @document = document.class.find(document.id) end def call document.update!(pdf_file: file) end private def pdf_klass return ::Dorsale::BillingMachine.invoice_pdf_model if document.is_a?(::Dorsale::BillingMachine::Invoice) return ::Dorsale::BillingMachine.quotation_pdf_model if document.is_a?(::Dorsale::BillingMachine::Quotation) end def pdf_data @pdf_data ||= pdf_klass.new(document).tap(&:build).render_with_attachments end def file @file ||= StringIO.new(pdf_data) end class StringIO < ::StringIO def original_filename @original_filename ||= "#{SecureRandom.uuid}.pdf" end end end
Version data entries
16 entries across 16 versions & 1 rubygems