ActiveRecord::Extensions 0.2.0 Released!
on December 22, 2006 @ 07:50 AM

ActiveRecord::Extensions 0.2.0 is released! Download it here .

Updates include:
  • Changes to the to_csv method to support an API compatible with the ToCSV plugin by Chris Abad
  • Added support for SQLite and SQLite3
  • Added “does_not_match” suffix for :conditions which want to negate a regex
  • Added “not_between” suffix for :conditions which want to negate a range
  • Converted test database schema to use migrations, and added tasks to load test database

to_csv updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  class Developer < ActiveRecord::Base ; end
  developers = Developer.find( :all )

  # Output default headers, this is implicit if headers is not provided
  csv  = developers.to_csv( :headers => true )

  # Output no headers
  csv = developers.to_csv( :headers => false )

  # Output only the following columns
  csv = developers.to_csv( :only=>[ :id, :name ] )
 
  # Output all columns except the following
  csv = developers.to_csv( :except => [ :id, :name ] )

Updates to better finders

I was typing some code today and I was using Ranges and Regexps. It just felt write to say that something_does_not_match when matching between a Regular Expression. And then I decided to add “not_between” for Ranges.

1
2
3
4
5
6
7
  class Developer < ActiveRecord::Base ; end
  
  # find all developers whose name does not match the regex
  Developer.find :all, :conditions => { :name_does_not_match => '^Zach' }

  # find all developers whose IQ is not between 80 and 120
  Developer.find :all, :conditions => { :iq_not_between => ( 80 .. 120 ) }

Running ActiveRecord::Extensions Tests

ActiveRecord::Extensions provides a great testing suite. Just run “rake -T” to see all of the supported tasks. In 0.2.0 the ability to load a test database from migrations has been added.

     # Usage
     rake db:test:prepare_<db>

     # IE:
     rake db:test:prepare_mysql

     # Then run your tests:
     rake test:mysql

     # And don't forget to test against activerecord
     rake test:activerecord:mysql ~/rails_trunk/activerecord 

The only prerequisite of the above is to make sure that your connection is specified correctly for the database you want to test. To do this go into the tests/connections/native_/connection.rb file and update the database configuration.

Enjoy 0.2.0!

For any questions or comments let me know.
  • zach DOT dennis AT gmail DOT com