Module: CouchRest::Validation::ValidatesLength

Included in:
ClassMethods
Defined in:
lib/couchrest/validation/validators/length_validator.rb

Overview

class LengthValidator

Instance Method Summary (collapse)

Instance Method Details

- (Object) validates_length(*fields)



132
133
134
135
# File 'lib/couchrest/validation/validators/length_validator.rb', line 132

def validates_length(*fields)
  warn "[DEPRECATION] `validates_length` is deprecated.  Please use `validates_length_of` instead."
  validates_length_of(*fields)
end

- (Object) validates_length_of(*fields)

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


class Page

  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)


127
128
129
130
# File 'lib/couchrest/validation/validators/length_validator.rb', line 127

def validates_length_of(*fields)
  opts = opts_from_validator_args(fields)
  add_validator_to_context(opts, fields, CouchRest::Validation::LengthValidator)
end