Module: DataMapper::Validate::ValidatesIsPrimitive

Included in:
ClassMethods
Defined in:
lib/dm-validations/primitive_validator.rb

Overview

class PrimitiveValidator

Instance Method Summary collapse

Instance Method Details

#validates_is_primitive(*fields) ⇒ Object

Validates that the specified attribute is of the correct primitive type.

Examples:

Usage

require 'dm-validations'

class Person
  include DataMapper::Resource

  property :birth_date, Date

  validates_is_primitive :birth_date

  # a call to valid? will return false unless
  # the birth_date is something that can be properly
  # casted into a Date object.
end

53
54
55
56
# File 'lib/dm-validations/primitive_validator.rb', line 53

def validates_is_primitive(*fields)
  opts = opts_from_validator_args(fields)
  add_validator_to_context(opts, fields, DataMapper::Validate::PrimitiveValidator)
end