public
Description: dynamic, more readable block-driven validation for ActiveRecord models.
Clone URL: git://github.com/fhwang/validates_with_block.git
Francis Hwang (author)
Thu Jun 12 15:03:25 -0700 2008
name age message
file .gitignore Wed May 14 09:45:04 -0700 2008 adding tests [Francis Hwang]
file MIT-LICENSE Thu May 15 07:45:06 -0700 2008 added MIT-LICENSE [Francis Hwang]
file README Wed May 14 10:04:43 -0700 2008 cleanup doco [Francis Hwang]
file Rakefile Thu Jun 12 15:03:25 -0700 2008 Rakefile tweak [Francis Hwang]
file init.rb Wed May 14 08:31:35 -0700 2008 first commit [Francis Hwang]
file install.rb Wed May 14 08:31:35 -0700 2008 first commit [Francis Hwang]
directory lib/ Wed Jun 11 13:52:04 -0700 2008 Include all instance methods when checking attr... [binary42]
directory tasks/ Wed May 14 08:31:35 -0700 2008 first commit [Francis Hwang]
directory test/ Wed Jun 11 13:39:20 -0700 2008 added a test [Francis Hwang]
file uninstall.rb Wed May 14 08:31:35 -0700 2008 first commit [Francis Hwang]
README
= ValidatesWithBlock

A plugin that allows for dynamic, more readable block-driven validation for ActiveRecord models.

== Installing as a plugin

EDGE Rails has support for plugin installation from Git, so if you're using EDGE Rails you can install with:

  ./script/plugin install git://github.com/fhwang/validates_with_block.git

We're maintaining an SVN clone of the plugin for those of you who aren't on EDGE Rails yet:

  ./script/plugin install svn://rubyforge.org/var/svn/nycrb/validates_with_block

== Using ValidatesWithBlock

Basically this plugin is meant to help you make your models a little cleaner if you've got a lot of validations. Instead 
of:

  validates_presence_of   :login, :message => 'Please enter a login.'
  validates_uniqueness_of :login, :case_sensitive => false
  validates_format_of     :login, :with => /\A\w*\Z/
  validates_length_of     :login, :within => 4..15
  
You can write:

  validates_login do |login|
    login.present   :message => 'Please enter a login.'
    login.unique    :case_sensitive => false
    login.formatted :with => /\A\w*\Z/
    login.length    :within => 4..15
  end
                               
The methods map to validation methods as follows:

  login.confirmed          => validates_confirmation_of
  login.formatted          => validates_format_of
  login.formatted_as_email => validates_email_format_of
  login.length             => validates_length_of
  login.present            => validates_presence_of
  login.unique             => validates_uniqueness_of

== formatted_as_email

You may have noticed the inclusion of validates_email_format_of; that's not a standard ActiveRecord validation. It comes 
from the very useful validates_email_format_of plugin, which is available at 
http://code.dunae.ca/validates_email_format_of.html . Obviously formatted_as_email won't work if you haven't installed 
this plugin.

== Contact

If you have any bugs, questions, etc., please feel to email me:

Francis Hwang
francis@diversionmedia.com