ActiveRecord::Extensions 0.1.0 Released! 17 Dec 2006
ActiveRecord::Extensions 0.1.0 is released and it’s getting some press! An article has been “published”:http://www.rubyinside.com/advent2006/17-extendingar.html on “Ruby Inside’s Advent Calendar”:http://www.rubyinside.com/advent2006/ . Thanks to Peter Cooper for publishing the article.

Release Notes

ActiveRecord::Extensions 0.1.0 features:

  • to_csv functionality for Arrays returned by ActiveRecord::Base.find methods
  • to_csv_file functionality for Arrays returned by ActiveRecord::Base.find methods
  • Custom query object support for ActiveRecord::Base.find
  • Official better finder support for MySQL and PostgreSQL
  • Generic better finder support for all other database adapter supported by ActiveRecord
  • Official import functionality support for MySQL and PostgreSQL
  • Generic import functionality support for all other database adapters supported by ActiveRecord
  1. 0 is actually the seventh release of ActiveRecord::Extensions, it’s version number is so low because as more adapters are officially supported, it will quickly rise towards a 1.0.0 release.

Official Support vs. Generic Support

Official support means that I have tests for the adapter in question, and it without a doubt works with ActiveRecord::Extensions.

Generic support means that I have implemented default ActiveRecord compatibility with all of the features. It should work with all supported adapters of ActiveRecord, but there are not tests in my library testing those adapters.

to_csv

tocsv_ has been added as a method to all Arrays returned by ActiveRecord::Base.find. You can now quickly and painlessly turn ActiveRecord objects into CSV format. This functionality does rely on faster_csv (1.0.0 or higher) being installed:

class Project < ActiveRecord::Base ; end
projects = Project.find( :all )
csv = projects.to_csv

You can also pass in an array of headers that you want as Strings or Symbols:

csv = projects.to_csv( :headers => [ :project_name, :started_on, :estimated_due_date ] )

to_csv_file

tocsv_file_ has been added as a method to all Arrays returned by ActiveRecord::Base.find. It gives you the ability to quickly csv files, much like it’s sibling function tocsv_. Instead of simply returning a CSV string it writes a file to disk:

projects = Project.find( :all )

# Writes projects.csv to disk using the 'w' file mode operation
projects.to_csv_file( 'projects.csv' )

# Writes projects.csv to disk using the 'a' (append) file mode operation. 
# Any IO mode is supported as the second parameter.
projects.to_csv_file( 'projects.csv', 'a' )

# Writes projects.csv to disk specifying what columns headers to use:
projects.to_csv_file(
     'projects.csv', 
     :headers=> [ :project_name, :started_on, :estimated_due_date ] 
)

Refactorings

This release also includes some refactorings of how ActiveRecord::Extensions internals work to support better extensibility down the road.

Download and Install

“Download it now from rubyforge!”:http://rubyforge.org/frs/?group_id=2113 .

Installation is simple. You can put it in your Rails application by placing the extracted directory in your RAILS_ROOT/vendor/plugins directory or you can put it in any application and require the init.rb file included in the ar-extensions-0.1.0./ directory.

Upcoming in the next release will be easier installation via “gem install” or installation as a Rails plugin from your rails application using “script/plugin”.

Contact the Developer

Any questions, comments or bugs please feel free to use the Project Tracking features on the “RubyForge project site”:http://rubyforge.org/tracker/?group_id=2113

  • Email: Zach Dennis - zach DOT dennis AT gmail DOT com

blog comments powered by Disqus