Class: Notes::PositionSerializedSizeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/notes/position_serialized_size_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'app/validators/notes/position_serialized_size_validator.rb', line 5

def validate_each(record, attribute, value)
  max_bytesize = options.fetch(:max_bytesize)

  return unless record.new_record? || record.will_save_change_to_attribute?(attribute)

  return unless raw_value(value).bytesize > max_bytesize

  record.errors.add(attribute, "is too large (max #{max_bytesize} bytes)")
end