Class: Mongoid::Validatable::CollectionSizeValidator

Inherits:
LengthValidator
  • Object
show all
Defined in:
lib/custom_fields/extensions/mongoid/validatable/collection_size.rb

Overview

Validates that the specified collections do or do not match a certain size.

Examples:

Set up the collection size validator.


class Person
  include Mongoid::Document
  has_many :addresses

  validates_collection_size_of :addresses, in: 1..10
end

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



17
18
19
20
21
# File 'lib/custom_fields/extensions/mongoid/validatable/collection_size.rb', line 17

def validate_each(record, attribute, value)
  value = collection_to_size(record, attribute)

  super(record, attribute, value)
end