Class: MongoMapper::Validations::ValidatesInclusionOf

Inherits:
Validatable::ValidationBase
  • Object
show all
Defined in:
lib/mongomapper/validations.rb

Instance Method Summary collapse

Instance Method Details

#message(instance) ⇒ Object



64
65
66
# File 'lib/mongomapper/validations.rb', line 64

def message(instance)
  super || "is not in the list"
end

#valid?(instance) ⇒ Boolean

Returns:



56
57
58
59
60
61
62
# File 'lib/mongomapper/validations.rb', line 56

def valid?(instance)
  value = instance[attribute]
  return true if allow_nil && value.nil?
  return true if allow_blank && value.blank?
  
  within.include?(value)
end