Module: DataMapper::Validations::ValidatesLength

Extended by:
Deprecate
Included in:
ClassMethods
Defined in:
lib/dm-validations/validators/length_validator.rb

Overview

class LengthValidator

Instance Method Summary collapse

Instance Method Details

#validates_length_of(*fields) ⇒ Object

Validates that the length of the attribute is equal to, less than, greater than or within a certain range (depending upon the options you specify).

Examples:

Usage

require 'dm-validations'

class Page
  include DataMapper::Resource

  property high, Integer
  property low, Integer
  property just_right, Integer

  validates_length_of :high, :min => 100000000000
  validates_length_of :low, :equals => 0
  validates_length_of :just_right, :within => 1..10

  # a call to valid? will return false unless:
  # high is greater than or equal to 100000000000
  # low is equal to 0
  # just_right is between 1 and 10 (inclusive of both 1 and 10)

Parameters:

  • [Boolean] (Hash)

    a customizable set of options

  • [Range] (Hash)

    a customizable set of options



242
243
244
# File 'lib/dm-validations/validators/length_validator.rb', line 242

def validates_length_of(*fields)
  validators.add(LengthValidator, *fields)
end