Class: Decidim::ExportJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/decidim/export_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(user, component, name, format, resource_id = nil, filters = nil) ⇒ Object

rubocop:disable Metrics/ParameterLists



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/decidim/export_job.rb', line 8

def perform(user, component, name, format, resource_id = nil, filters = nil)
  export_manifest = component.manifest.export_manifests.find do |manifest|
    manifest.name == name.to_sym
  end

  collection = export_manifest.collection.call(component, user, resource_id)
  collection = collection.ransack(filters).result if collection.respond_to?(:ransack) && filters
  serializer = export_manifest.serializer

  export_data = Decidim::Exporters.find_exporter(format).new(collection, serializer).export

  ExportMailer.export(user, name, export_data).deliver_now
end