Class: EacRailsUtils::ImmutableValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/eac_rails_utils/immutable_validator.rb

Constant Summary collapse

DEFAULT_MESSAGE =
'cannot be changed'

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, _value) ⇒ Object



7
8
9
10
11
12
# File 'app/validators/eac_rails_utils/immutable_validator.rb', line 7

def validate_each(record, attribute, _value)
  return if record.new_record?
  return unless record.send("#{attribute}_changed?")

  record.errors[attribute] << (options[:message] || DEFAULT_MESSAGE)
end