Module: DataMapper::Validate::ValidatesIsAccepted

Included in:
ClassMethods
Defined in:
lib/gems/dm-validations-0.9.9/lib/dm-validations/acceptance_validator.rb

Overview

class AcceptanceValidator

Instance Method Summary collapse

Instance Method Details

#validates_is_accepted(*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_is_accepted :license_agreement, :accept => "1"
  validates_is_accepted :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:

  • :allow_nil<Boolean> (Hash)

    a customizable set of options

  • :accept<Array> (Hash)

    a customizable set of options



69
70
71
72
# File 'lib/gems/dm-validations-0.9.9/lib/dm-validations/acceptance_validator.rb', line 69

def validates_is_accepted(*fields)
  opts = opts_from_validator_args(fields)
  add_validator_to_context(opts, fields, DataMapper::Validate::AcceptanceValidator)
end