Roles1 is a project mainly written in RUBY and JAVASCRIPT, it's free.
See lib/generators/roles_and_permissions/USAGE.
Next step: extract into a gem.