ActiveRecord::Extensions 0.2.0 Released! 22 Dec 2006
ActiveRecord::Extensions 0.2.0 is released! Download it “here”:http://rubyforge.org/frs/?group_id=2113 .

Updates include:

  • Changes to the tocsv_ method to support an API compatible with the “ToCSV plugin”:http://blog.integralimpressions.com/articles/2006/09/01/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

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 somethingdoes_not_match_ when matching between a Regular Expression. And then I decided to add “not_between” for Ranges.

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_DB/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


blog comments powered by Disqus