class FunWithJsonApi::Attributes::UuidV4Attribute
Attribute
that only accepts a properly generated and formatted UUID version 4 as described in RFC 4122
Constants
Public Instance Methods
decode(value)
click to toggle source
# File lib/fun_with_json_api/attributes/uuid_v4_attribute.rb, line 9 def decode(value) return value if value.nil? || value =~ UUID_V4_REGEX raise build_invalid_attribute_error(value) end
Private Instance Methods
build_invalid_attribute_error(value)
click to toggle source
# File lib/fun_with_json_api/attributes/uuid_v4_attribute.rb, line 17 def build_invalid_attribute_error(value) payload = ExceptionPayload.new payload.detail = I18n.t('fun_with_json_api.exceptions.invalid_uuid_v4_attribute') payload.pointer = "/data/attributes/#{name}" Exceptions::InvalidAttribute.new( "Value is not a RFC 4122 Version 4 UUID: #{value.class.name}", payload ) end