Sha256: 30f822f336917a5205d740c8eeef079596da4c5e2f599274109c27ac8aed4ea0

Contents?: true

Size: 705 Bytes

Versions: 6

Compression:

Stored size: 705 Bytes

Contents

require 'csv'

module Dossier
  class StreamCSV
    attr_reader :headers, :collection

    def initialize(collection, headers = nil)
      @headers    = headers || collection.shift unless false === headers
      @collection = collection
    end

    def each
      yield headers.to_csv if headers?
      collection.each do |record|
        yield record.to_csv
      end
    rescue => e
      if Rails.application.config.consider_all_requests_local
        yield e.message
        e.backtrace.each do |line|
          yield "#{line}\n"
        end
      else
        yield "We're sorry, but something went wrong." 
      end
    end

    private

    def headers?
      headers.present?
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dossier-3.0.0.pre lib/dossier/stream_csv.rb
dossier-2.13.1 lib/dossier/stream_csv.rb
dossier-2.12.2 lib/dossier/stream_csv.rb
dossier-2.12.1 lib/dossier/stream_csv.rb
dossier-2.12.0 lib/dossier/stream_csv.rb
dossier-2.11.0 lib/dossier/stream_csv.rb