Class/Module Index [+]

Quicksearch

DataMapper::Validations::ValidatesWithin

Public Instance Methods

validates_within(*fields) click to toggle source

Validates that the value of a field is within a range/set.

This validation is defined by passing a field along with a :set parameter. The :set can be a Range or any object which responds to the include? method (an array, for example).

@example Usage

require 'dm-validations'

class Review
  include DataMapper::Resource

  STATES = ['new', 'in_progress', 'published', 'archived']

  property :title, String
  property :body, String
  property :review_state, String
  property :rating, Integer

  validates_within :review_state, :set => STATES
  validates_within :rating,       :set => 1..5

  # a call to valid? will return false unless
  # the two properties conform to their sets
end
# File lib/dm-validations/validators/within_validator.rb, line 69
def validates_within(*fields)
  validators.add(WithinValidator, *fields)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.