Class: Hotwire::Response::Csv

Inherits:
Base
  • Object
show all
Defined in:
lib/hotwire/response/csv.rb

Overview

Specialization responsible for producing responses in CSV format.

Instance Attribute Summary

Attributes inherited from Base

#columns, #data

Attributes inherited from Base

#errors

Instance Method Summary collapse

Methods inherited from Base

#add_column, #add_columns, #initialize, #set_data

Methods inherited from Base

#add_error, #initialize, #valid?, #validate

Constructor Details

This class inherits a constructor from Hotwire::Response::Base

Instance Method Details

#bodyObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/hotwire/response/csv.rb', line 5

def body
  rsp = []
  CSV::Writer.generate(rsp) do |csv|
    csv << columns.map { |col| col[:label] || col[:id] || col[:type] }
    data.each do |datarow|
      csv << datarow
    end
  end
  return rsp.join
end