Significantly reduce code length for rake api tasks

Mostly just clean up Ruby and ActiveRecord usage to be more concise.

This branch includes PR #166, better to review and merge that one first.

Moved to a separate PR ~~Fixes one deprecation that prevents the API from working on Ruby 1.9: `require 'ftools'` becomes `require 'fileutils'` (still works fine on 1.8).~~