module SmartCsv module Exportable module ClassMethods def self.to_csv(*args) find(:all).to_csv(*args) end end module InstanceMethods def export_columns(format = nil) self.class.content_columns.map(&:name) - ['created_at', 'updated_at'] end def to_row(format = nil) export_columns(format).map { |c| self.send(c) } end end def self.included(receiver) receiver.extend ClassMethods receiver.send :include, InstanceMethods end end end ActiveRecord::Base.send :include, SmartCsv::Exportable