Class: ValidatesImmutability::ImmutableValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ValidatesImmutability::ImmutableValidator
- Defined in:
- lib/validates_immutability/immutable_validator.rb
Direct Known Subclasses
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 .key?(:on) raise ArgumentError, "Unknown option :on" end return if record.new_record? if record.send("#{attribute}_changed?") record.errors.add(attribute, ([:message] || "can't be modified")) end end |