public
Description: Add validations directly to instances of your AR model, not just at the class-level
Homepage: http://evang.eli.st/blog/2007/1/20/instance-validations-plugin
Clone URL: git://github.com/pat-maddox/instance_validations.git
name age message
file README Fri Jan 26 19:15:08 -0800 2007 First import [pat]
file Rakefile Fri Jan 26 19:15:08 -0800 2007 First import [pat]
file init.rb Fri Jan 26 19:15:08 -0800 2007 First import [pat]
file install.rb Fri Jan 26 19:15:08 -0800 2007 First import [pat]
directory lib/ Fri Jan 26 19:15:08 -0800 2007 First import [pat]
directory spec/ Fri Jan 26 19:15:08 -0800 2007 First import [pat]
directory tasks/ Fri Jan 26 19:15:08 -0800 2007 First import [pat]
file uninstall.rb Fri Jan 26 19:15:08 -0800 2007 First import [pat]
README
InstanceValidations
===================

ActiveRecord lets you define validations at the class level.  This plugin lets you define validations for ActiveRecord 
instances.  Take the following ActiveRecord class:

  class Chicken < ActiveRecord::Base
    include InstanceValidations
    # Has two columns, name and home_town.  Only validate name
    validates_presence_of :name
  end

All instances of Chicken will require a name in order to be valid.  If you don't define any instance validations, you'll 
get the expected behavior:

  chicken = Chicken.new
  chicken.valid?     => false, will have an error on name
  
If you do specify instance validations, the class validations are ignored and only instance validations are used:

  chicken_without_a_name = Chicken.new
  class << chicken_without_a_name
    validates_presence_of :home_town
  end
  chicken_without_a_name.valid?                 # => false, will have an error on home_town but not name
  chicken_without_a_name.home_town = "Roostershire"
  chicken_without_a_name.valid?                 # => true
  
  
Written by Pat Maddox.  Released under the MIT License.
svn://evang.eli.st/public/plugins/instance_validations