Class: Decidim::DownloadYourDataExporter

Inherits:
Object
  • Object
show all
Defined in:
app/services/decidim/download_your_data_exporter.rb

Overview

Public: Generates a 7z(seven zip) file with data files ready to be persisted somewhere so users can download their data.

In fact, the 7z file wraps a ZIP file which finally contains the data files.

Constant Summary collapse

DEFAULT_EXPORT_FORMAT =
"CSV"
ZIP_FILE_NAME =
"download-your-data.zip"

Instance Method Summary collapse

Constructor Details

#initialize(user, path, password, export_format = DEFAULT_EXPORT_FORMAT) ⇒ DownloadYourDataExporter

Public: Initializes the class.

user - The user to export the data from. path - The String path where to write the zip file. password - The password to protect the zip file. export_format - The format of the data files inside the zip file. (CSV by default)



20
21
22
23
24
25
# File 'app/services/decidim/download_your_data_exporter.rb', line 20

def initialize(user, path, password, export_format = DEFAULT_EXPORT_FORMAT)
  @user = user
  @path = File.expand_path path
  @export_format = export_format
  @password = password
end

Instance Method Details

#exportObject



27
28
29
30
31
32
33
34
# File 'app/services/decidim/download_your_data_exporter.rb', line 27

def export
  tmpdir = Dir.mktmpdir("temporary-download-your-data-dir")
  user_data, user_attachments = data_and_attachments_for_user
  save_user_data(tmpdir, user_data)
  save_user_attachments(tmpdir, user_attachments)

  SevenZipWrapper.compress_and_encrypt(filename: @path, password: @password, input_directory: tmpdir)
end