Class: ImpExp::Exporters::Files

Inherits:
Base
  • Object
show all
Defined in:
app/services/imp_exp/exporters/files.rb

Instance Attribute Summary

Attributes inherited from Base

#logger, #models, #scoping_parent

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ImpExp::Exporters::Base

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/imp_exp/exporters/files.rb', line 8

def call
  super do
    tmp_file = Tempfile.new("exporters_files")
    zip = Zip::OutputStream.write_buffer(tmp_file) do |output_stream|
      models.each do |model|
        files = model.files(scoping_parent)
        next if files.empty?

        files.each do |active_storage_file|
          full_path = "#{model.files_directory_path}/#{model.filename(active_storage_file)}"
          add_entry_to_zip(output_stream, active_storage_file, full_path)
        end
      end
    end
    zip.flush
    tmp_file.rewind
    { zip_stream: tmp_file }
  end
end