Module: Validation

Module | Validation
In: | lib/assistance/validation.rb

The Validations module provides validation capabilities as a mixin. When included into a class, it enhances the class with class and instance methods for defining validations and validating class instances.

The Validation emulates the validation capabilities of ActiveRecord, and provides methods for validating acceptance, confirmation, presence, format, length and numericality of attributes.

To use validations, you need to include the Validation module in your class:

      class MyClass
        include Validation
        validates_length_of :password, :minimum => 6
      end

### Methods

errors included valid? validate

### Classes and Modules

Module Validation::ClassMethods
Class Validation::Errors
Class Validation::Generator

### Public Class methods

included(c)

Includes the Validation class methods into the including class.

[Source]

        # File lib/assistance/validation.rb, line 18
    18:   def self.included(c)
    19:     c.extend ClassMethods
    20:   end

### Public Instance methods

errors()

Returns the validation errors associated with the object.

[Source]

        # File lib/assistance/validation.rb, line 23
    23:   def errors
    24:     @errors ||= Errors.new
    25:   end

valid?()

Validates the object and returns true if no errors are reported.

[Source]

        # File lib/assistance/validation.rb, line 34
    34:   def valid?
    35:     validate
    36:     errors.empty?
    37:   end

validate()

Validates the object.

[Source]

        # File lib/assistance/validation.rb, line 28
    28:   def validate
    29:     errors.clear
    30:     self.class.validate(self)
    31:   end

[Validate]