Module N::Validation
In: lib/glue/validation.rb

Implements a meta-language for validating managed objects. Typically used in Validator objects but can be included in managed objects too.

Example

class User

              prop_accessor :name, String
              prop_accessor :level, Fixnum

              validate_length :name, :range => 2..6
              validate_unique :name, :msg => :name_allready_exists
              validate_format :name, :format => /[a-z]*/, :msg => 'invalid format', :on => :create
      end

      class N::CustomUserValidator
              include N::Validation
              validate_length :name, :range => 2..6, :msg_short => :name_too_short, :msg_long => :name_too_long
      end

      user = @request.fill(User.new)
      user.level = 15

      unless user.valid?
              user.save
      else
              p user.errors[:name]
      end

      unless user.save
              p user.errors.on(:name)
      end

      unless errors = N::CustomUserValidator.errors(user)
              user.save
      else
              p errors[:name]
      end

Methods

Classes and Modules

Module N::Validation::MetaLanguage
Class N::Validation::Errors

Attributes

errors  [RW]  If the validate method returns true, this attributes holds the errors found.

Public Class methods

Evaluate the ‘validate’ method for the calling class.

WARNING: for the moment only evaluates for on == :save

Public Instance methods

Call the validate method for this object. If validation errors are found, sets the @errors attribute to the Errors object and returns true.

[Validate]