Module | DataMapper::Validations::ValidatesWithin |
In: |
lib/dm-validations/validators/within_validator.rb
|
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