Sha256: 180ac2a4408100eef96ed60329ac8a48b1b35c10d24e01dd41a1d18b8a113348
Contents?: true
Size: 793 Bytes
Versions: 11
Compression:
Stored size: 793 Bytes
Contents
class UuidValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value, options) record.errors[attribute] << (options[:message] || I18n.t('flash_validators.errors.messages.uuid')) end end private def valid_format?(value, options) case options[:version] when 3 value =~ /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i when 4 value =~ /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i when 5 value =~ /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i else value =~ /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i end end def valid?(value, options) valid_format?(value, options) end end
Version data entries
11 entries across 11 versions & 1 rubygems