Module: Decidim::ZipStream::Writer
- Included in:
- DataPortabilityExporter
- Defined in:
- app/services/decidim/zip_stream/zip_stream_writer.rb
Instance Method Summary collapse
- #add_attachments_to_zip_stream(out, export_attachments) ⇒ Object
- #add_user_data_to_zip_stream(out, user_data) ⇒ Object
-
#cache_attachment_from_aws(uploader) ⇒ Object
Retrieves the file from AWS and stores it into a temporal cache.
Instance Method Details
#add_attachments_to_zip_stream(out, export_attachments) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/decidim/zip_stream/zip_stream_writer.rb', line 19 def (out, ) .each do || next if .last.nil? folder_name = .first.parameterize .last.each do || next if .file.nil? case .fog_provider when "fog" # file system next unless File.exist?(.file.file) when "fog/aws" () else Rails.logger.info "Carrierwave fog_provider not supported by DataPortabilityExporter for attachment: #{}" next end = .file.file out.put_next_entry("#{folder_name}/#{.file.filename}") File.open() do |f| out << f.read end CarrierWave.clean_cached_files! end end end |
#add_user_data_to_zip_stream(out, user_data) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/decidim/zip_stream/zip_stream_writer.rb', line 6 def add_user_data_to_zip_stream(out, user_data) user_data.each do |element| filename_file = element.last.filename(element.first.parameterize) out.put_next_entry(filename_file) if element.last.read.presence out.write element.last.read else out.write "No data" end end end |
#cache_attachment_from_aws(uploader) ⇒ Object
Retrieves the file from AWS and stores it into a temporal cache. Once the file is cached, the uploader returns a local ‘CarrierWave::SanitizedFile` instead of a fog file that acts as a proxy to the remote file.
50 51 52 53 |
# File 'app/services/decidim/zip_stream/zip_stream_writer.rb', line 50 def (uploader) uploader.cache_stored_file! uploader.retrieve_from_cache!(uploader.cache_name) end |