Class: Decidim::DownloadYourDataExporter
- Inherits:
-
Object
- Object
- Decidim::DownloadYourDataExporter
- Includes:
- TranslatableAttributes
- Defined in:
- app/services/decidim/download_your_data_exporter.rb
Overview
Public: Generates a zip archive with data files ready to be persisted somewhere so users can download their data.
Constant Summary collapse
- DEFAULT_EXPORT_FORMAT =
"CSV"- ZIP_FILE_NAME =
"download-your-data.zip"
Instance Method Summary collapse
-
#export(retries: 0) ⇒ Object
i18n-tasks-use t(“decidim.download_your_data.show.download_your_data”).
-
#initialize(user, name, export_format = DEFAULT_EXPORT_FORMAT) ⇒ DownloadYourDataExporter
constructor
Public: Initializes the class.
Methods included from TranslatableAttributes
#attachment?, #default_locale?
Constructor Details
#initialize(user, name, export_format = DEFAULT_EXPORT_FORMAT) ⇒ DownloadYourDataExporter
Public: Initializes the class.
user - The user to export the data from. name - The name of the export in private area export_format - The format of the data files inside the zip file. (CSV by default)
18 19 20 21 22 |
# File 'app/services/decidim/download_your_data_exporter.rb', line 18 def initialize(user, name, export_format = DEFAULT_EXPORT_FORMAT) @user = user @export_format = export_format @name = name end |
Instance Method Details
#export(retries: 0) ⇒ Object
i18n-tasks-use t(“decidim.download_your_data.show.download_your_data”)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/services/decidim/download_your_data_exporter.rb', line 25 def export(retries: 0) data.rewind user_export = user.private_exports.build(file_size: data.length) user_export.export_type = name user_export.content_type = "application/zip" user_export.expires_at = Decidim.download_your_data_expiry_time.from_now user_export. = {} user_export.save! user_export.file.attach(io: data, filename: "#{name}.zip", content_type: "application/zip") return user_export.reload if user_export.reload.file.attached? return user_export.reload if retries >= 3 user_export.destroy! export(retries: retries + 1) end |