juliamae / soft_validations

This Ruby on Rails plugin provides an additional Errors object, referred to as warnings, to ActiveRecord objects. Unlike validations, soft validations are not tied in to an AR object's lifecycle and can be used to specify recommended states for data.

This URL has Read+Write access

name age message
file CHANGELOG Fri Jan 18 14:38:12 -0800 2008 Adding CHANGELOG. [juliamae]
file MIT-LICENSE Fri Jan 18 10:14:49 -0800 2008 Initial checkin of blank plugin. [juliamae]
file README Fri Jan 18 13:00:32 -0800 2008 Release 0.1 [juliamae]
file Rakefile Fri Jan 18 10:14:49 -0800 2008 Initial checkin of blank plugin. [juliamae]
file init.rb Fri Jan 18 13:00:32 -0800 2008 Release 0.1 [juliamae]
file install.rb Fri Jan 18 10:14:49 -0800 2008 Initial checkin of blank plugin. [juliamae]
directory lib/ Mon Jun 16 16:30:50 -0700 2008 Updating to be 2.1.0-compliant. [juliamae]
directory tasks/ Fri Jan 18 10:14:49 -0800 2008 Initial checkin of blank plugin. [juliamae]
directory test/ Mon Jun 16 16:30:50 -0700 2008 Updating to be 2.1.0-compliant. [juliamae]
file uninstall.rb Fri Jan 18 10:14:49 -0800 2008 Initial checkin of blank plugin. [juliamae]
README
SoftValidations
===============

This plugin provides an additional Errors object, referred to as warnings, to ActiveRecord objects. The warnings object 
is not tied in to a model's life cycle. Thus, an ActiveRecord object can be saved while still having messages in its 
warnings. This might be useful for sites that would want to keep track of recommended fields for users to complete, or 
sites with large amounts of erroneous imported data which might benefit from suspending some validations for a little 
while.


Example
=======

Use SoftValidations::Validation#soft_validation to add a descriptive declaration of an ActiveRecord object's desired 
state in order to be considered complete. The methods or block passed to soft_validate should add a message to the 
class's warning collection.

  class Employee < ActiveRecord::Base
    soft_validate :should_have_first_name
    
    protected
    def should_have_first_name
      warnings.add(:first_name, "shouldn't be blank") unless attribute_present?(:first_name)
    end
  end

To generate warnings, you should first call complete?

  >> employee = Employee.new
  >> employee.complete? 
  => false
  >> employee.warnings.on(:first_name) 
  => "shouldn't be blank"


Copyright (c) 2008 Julia West, released under the MIT license