Module: DataMapper::Validations::ValidatesAcceptance

Extended by:
Deprecate
Included in:
ClassMethods
Defined in:
lib/dm-validations/validators/acceptance_validator.rb

Overview

class AcceptanceValidator

Instance Method Summary collapse

Instance Method Details

#validates_acceptance_of(*fields) ⇒ Object

Validates that the attributes’s value is in the set of accepted values.

Examples:

Usage

require 'dm-validations'

class Page
  include DataMapper::Resource

  property :license_agreement_accepted, String
  property :terms_accepted, String
  validates_acceptance_of :license_agreement, :accept => "1"
  validates_acceptance_of :terms_accepted, :allow_nil => false

  # a call to valid? will return false unless:
  # license_agreement is nil or "1"
  # and
  # terms_accepted is one of ["1", 1, "true", true, "t"]

Parameters:

  • [Boolean] (Hash)

    a customizable set of options

  • [Array] (Hash)

    a customizable set of options



71
72
73
# File 'lib/dm-validations/validators/acceptance_validator.rb', line 71

def validates_acceptance_of(*fields)
  validators.add(AcceptanceValidator, *fields)
end