<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -8,25 +8,14 @@ This simple plugin gives you the ability to call to_csv to a collection of activ
   @users = User.all
 
   #
-  # defaults are export header and all fields except id, and timestamps
+  # defaults are export headers and all fields
   #
 
   @users.to_csv
   @users.to_csv(:only =&gt; [:last_name, :role])
-  @users.to_csv(:timestamps =&gt; true, :id =&gt; true, :header =&gt; false)
+  @users.to_csv(:headers =&gt; false)
   @users.to_csv(:except =&gt; [:last_name, :role])
-  @users.to_csv(:except =&gt; :role, :methods =&gt; [:name, :admin?])
-
-  #
-  # NEW FEATURE
-  # Now you can call methods of a has_one or belongs_to association 
-  # (for now you can go up/down 1 level)
-  #
-
-  # A note belongs_to :user
-  @notes = Note.all
-  @notes.to_csv(:methods =&gt; [{:user =&gt; :name}])
-
+  @users.to_csv(:except =&gt; :role, :methods =&gt; :admin?)
 
 
 == Real life example
@@ -73,7 +62,7 @@ I got ideas and influence from Mike Clarks recipe #35 in Rails Recipes book, som
 == Note
 
 Does not work on a single activerecord, ie, User.first.to_csv.
-Cannot style output.
+
 
 
 Copyright (c) 2008 Ary Djmal, released under the MIT license</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -1,52 +1,26 @@
 class Array
   
   def to_csv(options = {})
+    return '' if self.empty?
+    
+    all_columns = self.first.class.columns.collect { |c| c.name.to_sym }
+    
     if options[:only]
       columns = options[:only].to_a
     else
-      columns = self.first.class.columns.collect {|c| c.name.to_sym} - options[:except].to_a
-      columns -= [:created_at, :updated_at] unless options[:timestamps] == true
-      columns -= [:id] unless options[:id] == true
+      columns = all_columns - options[:except].to_a
     end
     
-    # Expand methods, [{:user =&gt; [:name, :id]}] =&gt; [{:user =&gt; :name}, {:user =&gt; :id}]
-    if methods = options[:methods]
-      methods = methods.collect do |method|
-        if method.is_a?(Symbol)
-          method
-        else
-          if method[method.keys.first].is_a?(Array)
-            method[method.keys.first].collect {|association_method| [{method.keys.first =&gt; association_method}]}
-          else
-            method
-          end
-        end
-      end
-      columns &lt;&lt; methods
-    end
+    columns = columns &amp; all_columns
+    
+    columns += options[:methods].to_a
     
-    columns = columns.flatten
+    return '' if columns.empty?
     
     output = FasterCSV.generate do |csv|
-      
-      unless options[:header] == false
-        csv &lt;&lt; columns.collect do |column|
-          if column.is_a?(Symbol)
-            column
-          else
-            &quot;#{column.keys.first}_#{column[column.keys.first]}&quot;
-          end
-        end
-      end 
-      
+      csv &lt;&lt; columns unless options[:headers] == false
       self.each do |item|
-        csv &lt;&lt; columns.collect do |column|
-          if column.kind_of?(Hash)
-            item.send(column.keys.first).send(column[column.keys.first])
-          else
-            item.send(column)
-          end
-        end
+        csv &lt;&lt; columns.collect { |column| item.send(column) }
       end
     end
     </diff>
      <filename>lib/to_csv.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,20 +12,40 @@ class ToCsvTest &lt; Test::Unit::TestCase
     @users &lt;&lt; User.new(:id =&gt; 2, :name =&gt; 'Nati', :age =&gt; 21)
   end
 
+  def test_with_empty_array
+    assert_equal( &quot;&quot;, [].to_csv )
+  end
+
   def test_with_no_options
-    assert_equal( &quot;name,age\nAry,24\nNati,21\n&quot;, @users.to_csv )
+    assert_equal( &quot;id,name,age\n1,Ary,24\n2,Nati,21\n&quot;, @users.to_csv )
   end
   
-  def test_with_id
-    assert_equal( &quot;id,name,age\n1,Ary,24\n2,Nati,21\n&quot;, @users.to_csv(:id =&gt; true) )
+  def test_with_no_headers
+    assert_equal( &quot;1,Ary,24\n2,Nati,21\n&quot;, @users.to_csv(:headers =&gt; false) )
   end
   
   def test_with_only
     assert_equal( &quot;name\nAry\nNati\n&quot;, @users.to_csv(:only =&gt; :name) )
   end
   
+  def test_with_empty_only
+    assert_equal( &quot;&quot;, @users.to_csv(:only =&gt; &quot;&quot;) )
+  end
+  
+  def test_with_only_and_wrong_column_names
+    assert_equal( &quot;name\nAry\nNati\n&quot;, @users.to_csv(:only =&gt; [:name, :yoyo]) )
+  end
+  
+  def test_with_except
+    assert_equal( &quot;age\n24\n21\n&quot;, @users.to_csv(:except =&gt; [:id, :name]) )
+  end
+  
+  def test_with_except_and_only_should_listen_to_only
+    assert_equal( &quot;name\nAry\nNati\n&quot;, @users.to_csv(:except =&gt; [:id, :name], :only =&gt; :name) )
+  end
+  
   def test_with_except
-    assert_equal( &quot;age\n24\n21\n&quot;, @users.to_csv(:except =&gt; :name) )
+    assert_equal( &quot;id,name,age,is_old?\n1,Ary,24,false\n2,Nati,21,false\n&quot;, @users.to_csv(:methods =&gt; [:is_old?]) )
   end
   
 end</diff>
      <filename>test/to_csv_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,6 +10,10 @@ class User
   def self.columns
     COLUMNS.collect { |column| Column.new(column) }
   end
+  
+  def is_old?
+    age &gt; 40
+  end
 end
 
 class Column</diff>
      <filename>test/user_model.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e718e58cac8e485a815e279ed01236106ee1f4fe</id>
    </parent>
  </parents>
  <author>
    <name>Ary Djmal</name>
    <email>arydjmal@gmail.com</email>
  </author>
  <url>http://github.com/arydjmal/to_csv/commit/6fbf202981c53c3b8f923baceb2d353bdcebd260</url>
  <id>6fbf202981c53c3b8f923baceb2d353bdcebd260</id>
  <committed-date>2008-12-23T14:04:46-08:00</committed-date>
  <authored-date>2008-12-23T14:04:46-08:00</authored-date>
  <message>removed ability to call methods of associations, this is against rails best practices; added more tests;</message>
  <tree>d382fb333a22c1baf58893890f1a1b968413eada</tree>
  <committer>
    <name>Ary Djmal</name>
    <email>arydjmal@gmail.com</email>
  </committer>
</commit>
