Module: RailsCsvRenderer::Renderable
- Defined in:
- lib/rails_csv_renderer/renderable.rb
Instance Method Summary collapse
-
#to_custom_csv(options = {}) ⇒ Object
Converts an collection of active records to CSV formatted string Options is configuration set for generated CSV file.
Instance Method Details
#to_custom_csv(options = {}) ⇒ Object
Converts an collection of active records to CSV formatted string Options is configuration set for generated CSV file
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_csv_renderer/renderable.rb', line 9 def to_custom_csv( = {}) = .merge([:csv_options] || {}) if is_active_record? if !(model.respond_to?(:csv_header) || model.method_defined?(:csv_row)) || model.class_variable_defined?(:@@dynamic_generated_csv_methods) define_csv_methods() end end CSV.generate() do |csv| if is_active_record? csv << model.csv_header self.each do |obj| csv << obj.csv_row end else csv << self if respond_to?(:to_csv) end end end |