Sha256: 25f3e51f8cf7abced918144c16ccc91b7ee47c763ad22bfa375c90deaa32d7b9

Contents?: true

Size: 845 Bytes

Versions: 20

Compression:

Stored size: 845 Bytes

Contents

module ActiveList
  module Exporters
    class CsvExporter < AbstractExporter
      def file_extension
        'csv'
      end

      def mime_type
        Mime::CSV
      end

      def send_data_code
        record = 'r'
        code = generator.select_data_code(paginate: false)
        code << "data = ::CSV.generate do |csv|\n"
        code << "  csv << [#{columns_to_array(:header).join(', ')}]\n"
        code << "  for #{record} in #{generator.records_variable_name}\n"
        code << "    csv << [#{columns_to_array(:body, record: record).join(', ')}]\n"
        code << "  end\n"
        code << "end\n"
        code << "send_data(data, type: #{mime_type.to_s.inspect}, disposition: 'inline', filename: #{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i, '_') + '.#{file_extension}')\n"
        code.c
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
active_list-6.10.0 lib/active_list/exporters/csv_exporter.rb
active_list-6.9.4 lib/active_list/exporters/csv_exporter.rb
active_list-6.9.3 lib/active_list/exporters/csv_exporter.rb
active_list-6.9.2 lib/active_list/exporters/csv_exporter.rb
active_list-6.9.1 lib/active_list/exporters/csv_exporter.rb
active_list-6.9.0 lib/active_list/exporters/csv_exporter.rb
active_list-6.8.3 lib/active_list/exporters/csv_exporter.rb
active_list-6.8.2 lib/active_list/exporters/csv_exporter.rb
active_list-6.8.1 lib/active_list/exporters/csv_exporter.rb
active_list-6.8.0 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.6 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.5 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.4 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.3 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.2 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.1 lib/active_list/exporters/csv_exporter.rb
active_list-6.7.0 lib/active_list/exporters/csv_exporter.rb
active_list-6.6.2 lib/active_list/exporters/csv_exporter.rb
active_list-6.6.1 lib/active_list/exporters/csv_exporter.rb
active_list-6.6.0 lib/active_list/exporters/csv_exporter.rb