And have the write_returned_recordset_to_file write the returned data
with column headers to a file. I have some idea but they are not
class independent. Any sexy suggestions?
And have the write_returned_recordset_to_file write the returned data
with column headers to a file. I have some idea but they are not
class independent. Any sexy suggestions?
How about this?
require ‘faster_csv’
module FindToCSV
def self.included( cl )
cl.instance_eval "
alias :_original_find :find
def find( *args )
results = _original_find( *args )
results.extend( ArrayExtension ) if results.is_a?( Array )
results
end
"
end
module ArrayExtension
def to_csv( filename )
csv = FasterCSV.generate do |csv|
csv << self.first.attributes.sort.map{ |arr| arr.first }
self.each do |row|
csv << self.first.attributes.sort.map{ |arr| arr.last }
end
end
File.open( filename, “w” ){ |io| io.puts csv }
end
end
end
class Job < ActiveRecord::Base
include FindToCSV
end
so I can add headers to the csv file, and also exclude certain columns
easily
Ok, i just committed the first rendition to my svn repos for
ActiveRecored::Extensions with an initial test. I’ll add some test
cases for this later today and get the functionality committed.
This weekend ActiveRecord::Extensions will launch a new release so if
you can hold out until then you’ll be able to install it as
a plugin or as a gem. If not feel free to pull down from trunk, http://rubyforge.org/projects/arext/
Zach
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org