Module: Sequel::Plugins::CsvSerializer::DatasetMethods
- Defined in:
- lib/sequel/plugins/csv_serializer.rb
Instance Method Summary collapse
-
#to_csv(opts = {}) ⇒ Object
Return a CSV string representing an array of all objects in this dataset.
Instance Method Details
#to_csv(opts = {}) ⇒ Object
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.
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/sequel/plugins/csv_serializer.rb', line 162 def to_csv(opts = {}) opts = model.process_csv_serializer_opts({:columns=>columns}.merge!(opts)) items = opts.delete(:array) || self CSV.generate(opts) do |csv| items.each do |object| csv << opts[:headers].map{|header| object.send(header) } end end end |