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
182 def to_csv(opts = OPTS)
183   opts = model.process_csv_serializer_opts({:columns=>columns}.merge!(opts))
184   items = opts.delete(:array) || self
185   headers = opts[:headers]
186 
187   CsvSerializer.csv_call(:generate, opts) do |csv|
188     items.each do |object|
189       csv << headers.map{|header| object.public_send(header)}
190     end
191   end
192 end