Class: UuidValidator

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

Overview

UuidValidator Validates that the supplied value is a valid uuid by regular expression. This is a little more permissive than strictly governed by the UUID format, but we’re more likely to see technically ‘valid’ uuids, which just don’t map to a resource, so lets keep things simple.

Constant Summary collapse

UUID =
/\A[0-f]{8}-([0-f]{4}-){3}[0-f]{12}\z/

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



12
13
14
15
16
# File 'app/validators/uuid_validator.rb', line 12

def validate_each(record, attribute, value)
  return if value.blank? || UUID.match?(value)

  record.errors.add(attribute, :uuid)
end