require 'csv'

module DC

  module CSV

    def self.generate_csv(records, keys=nil)
      keys ||= records.first.keys
      ::CSV.generate do |csv|
        csv << keys
        records.each do |record|
          csv << keys.map {|key| record[key] }
        end
      end
    end

  end

end

require 'csv'

module DC

  module CSV

    def self.generate_csv(records, keys=nil)
      return if records.none?
      keys ||= records.first.keys
      ::CSV.generate do |csv|
        csv << keys
        records.each do |record|
          csv << keys.map {|key| record[key] }
        end
      end
    end

  end

end

Return immediately if the are no records to dump
Return immediately if the are no records to dump

On a fresh or lightly used install there are no records to dump
to CSV which was causing exceptions on the nightly emails
