Sha256: 8d26af89e3e2895f3b0f2884964cc96a87514b670c39921a94dda812b1249704

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module MrCommon
  module Registrations
    class ExportController < BaseController
      # Generates CSV data and sends as file download.
      def index
        send_data(registrations_csv, filename: filename)
      end

      private

        def registrations_csv
          fields = csv_fields
          fields.delete(:pre_registered?) unless MrCommon.registration_confirmation_strategy == :pre_register

          CSVRenderer.new(
            collection: MrCommon::Registration.all,
            decorator: MrCommon::RegistrationDecorator,
            fields: fields
          ).render
        end

        def csv_fields
          [
            :first_name,
            :last_name,
            :email,
            :company_name,
            :telephone,
            :zip_code,
            :country,
            :pre_registered?,
            :confirmed?,
            :created_at,
            :updated_at
          ]
        end

        def filename
          "Registrations-#{Date.today}.csv"
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mr_common-2.1.0 app/controllers/mr_common/registrations/export_controller.rb
mr_common-2.0.0 app/controllers/mr_common/registrations/export_controller.rb