module Sequel::Plugins::CsvSerializer::DatasetMethods

  1. lib/sequel/plugins/csv_serializer.rb

Methods

Public Instance

  1. to_csv

Public Instance methods

to_csv(opts = OPTS)

Return a CSV string representing an array of all objects in this dataset. Takes the same options as the instance method, and passes them to every instance. Accepts the same options as CSV.new, as well as the following options:

:array

An array of instances. If this is not provided, calls all on the receiver to get the array.

[show source]
    # File lib/sequel/plugins/csv_serializer.rb
171 def to_csv(opts = OPTS)
172   opts = model.process_csv_serializer_opts({:columns=>columns}.merge!(opts))
173   items = opts.delete(:array) || self
174   headers = opts[:headers]
175 
176   CSV.generate(**opts) do |csv|
177     items.each do |object|
178       csv << headers.map{|header| object.public_send(header)}
179     end
180   end
181 end