Class: Dossier::StreamCSV
- Inherits:
-
Object
- Object
- Dossier::StreamCSV
- Defined in:
- lib/dossier/stream_csv.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(collection, headers = nil) ⇒ StreamCSV
constructor
A new instance of StreamCSV.
Constructor Details
#initialize(collection, headers = nil) ⇒ StreamCSV
Returns a new instance of StreamCSV.
6 7 8 9 |
# File 'lib/dossier/stream_csv.rb', line 6 def initialize(collection, headers = nil) @headers = headers || collection.shift @collection = collection end |
Instance Method Details
#each ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dossier/stream_csv.rb', line 11 def each yield @headers.map { |header| Dossier::Formatter.titleize(header) }.to_csv @collection.each do |record| yield record.to_csv end rescue => e if Rails.application.config.consider_all_requests_local yield e. e.backtrace.each do |line| yield "#{line}\n" end else yield "We're sorry, but something went wrong." end end |