Class: CsvBuilders::Stream

Inherits:
CsvBuilder show all
Defined in:
lib/csv_builders/stream.rb

Constant Summary

Constants inherited from CsvBuilder

CsvBuilder::DEFAULT_BATCH_SIZE, CsvBuilder::DEFAULT_ORDER_BY, CsvBuilder::PREFIX_REGEX

Instance Attribute Summary

Attributes inherited from CsvBuilder

#rows_written

Instance Method Summary collapse

Methods inherited from CsvBuilder

#initialize, #rows_expected, #status, #truncated?

Constructor Details

This class inherits a constructor from CsvBuilder

Instance Method Details

#render(max_rows = 100_000) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
# File 'lib/csv_builders/stream.rb', line 5

def render(max_rows = 100_000)
  max_rows_including_header = max_rows + 1

  Enumerator.new do |csv|
    csv << CSV.generate_line(headers)

    each do |object|
      csv << CSV.generate_line(row(object))
    end
  end.lazy.take(max_rows_including_header) # rubocop: disable CodeReuse/ActiveRecord
end