Class: Mongoid::Validations::CollectionSizeValidator

Inherits:
Mongoid::Validatable::LengthValidator
  • Object
show all
Defined in:
lib/custom_fields/extensions/mongoid/validations/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_with_collection(record, attribute, value) ⇒ Object



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

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

  self.validate_each_without_collection(record, attribute, value)
end