Class: ValidatesImmutability::ImmutableValidator

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

Direct Known Subclasses

ImmutableValidator

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/validates_immutability/immutable_validator.rb', line 3

def validate_each(record, attribute, value)
  if options.key?(:on)
    raise ArgumentError, "Unknown option :on"
  end
  return if record.new_record?
  if record.send("#{attribute}_changed?")
    record.errors.add(attribute, (options[:message] || "can't be modified"))
  end
end