Module: DataMapper::Validations::ValidatesWithin

### Home Classes Methods

### In Files

- lib/dm-validations/validators/within_validator.rb

### Methods

- #validates_within

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::InvalidContextError
- DataMapper::Validate
- DataMapper::ValidationError
- DataMapper::Validations
- DataMapper::Validations::AbsenceValidator
- DataMapper::Validations::AcceptanceValidator
- DataMapper::Validations::AutoValidations
- DataMapper::Validations::AutoValidations::ModelExtension
- DataMapper::Validations::ClassMethods
- DataMapper::Validations::ConfirmationValidator
- DataMapper::Validations::Context
- DataMapper::Validations::ContextualValidators
- DataMapper::Validations::Format
- DataMapper::Validations::Format::Email
- DataMapper::Validations::Format::Url
- DataMapper::Validations::FormatValidator
- DataMapper::Validations::GenericValidator
- DataMapper::Validations::LengthValidator
- DataMapper::Validations::MethodValidator
- DataMapper::Validations::NumericalityValidator
- DataMapper::Validations::OrderedHash
- DataMapper::Validations::PresenceValidator
- DataMapper::Validations::PrimitiveTypeValidator
- DataMapper::Validations::UniquenessValidator
- DataMapper::Validations::UnknownValidationFormat
- DataMapper::Validations::ValidatesAbsence
- DataMapper::Validations::ValidatesAcceptance
- DataMapper::Validations::ValidatesConfirmation
- DataMapper::Validations::ValidatesFormat
- DataMapper::Validations::ValidatesLength
- DataMapper::Validations::ValidatesNumericality
- DataMapper::Validations::ValidatesPresence
- DataMapper::Validations::ValidatesPrimitiveType
- DataMapper::Validations::ValidatesUniqueness
- DataMapper::Validations::ValidatesWithBlock
- DataMapper::Validations::ValidatesWithMethod
- DataMapper::Validations::ValidatesWithin
- DataMapper::Validations::ValidationErrors
- DataMapper::Validations::WithinValidator
- Object

No matching classes.

# 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.