Class: ImmutableValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/mongoid/validators/immutable_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



2
3
4
5
6
# File 'lib/mongoid/validators/immutable_validator.rb', line 2

def validate_each(object, attribute, value)
  if object.send(:attribute_changed?, options[:field])  and object.send(:attribute_was, options[:field])
    object.errors.add(options[:field], 'is immutable and cannot be updated') and false
  end
end