module Sequel::Plugins::CsvSerializer::DatasetMethods

Public Instance Methods

to_csv(opts = OPTS) click to toggle source

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.

    # File lib/sequel/plugins/csv_serializer.rb
180 def to_csv(opts = OPTS)
181   opts = model.process_csv_serializer_opts({:columns=>columns}.merge!(opts))
182   items = opts.delete(:array) || self
183   headers = opts[:headers]
184 
185   CsvSerializer.csv_call(:generate, opts) do |csv|
186     items.each do |object|
187       csv << headers.map{|header| object.public_send(header)}
188     end
189   end
190 end