Module: EnjuExport::ActsAsMethods::ExportCSV::ClassMethods

Defined in:
lib/enju_export.rb

Instance Method Summary collapse

Instance Method Details

#generate_csv(ids, attrs, export_file, role = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/enju_export.rb', line 21

def generate_csv(ids, attrs, export_file, role = nil)
  export_file.sm_start!
  file = Tempfile.new("#{self.name.downcase}_")
  self.where('required_role_id >= ?', role.try(:id).to_i).find_each(:conditions => {:id => ids}) do |record|
    file.write(attrs.map{|attr| record.send(attr)}.join(',') + "\n")
  end
  file.close
  export_file.export = File.new(file.path)
  export_file.sm_complete!
end