class Acfs::Resource::Attributes::UUID

@api public

UUID attribute type. Use it in your model as an attribute type:

@example

class User < Acfs::Resource
  attribute :id, :uuid
end

Constants

UUID_REGEXP

Public Instance Methods

cast_value(value) click to toggle source

@api public

Check if given object looks like a UUID, eg:

`450b7a40-94ad-11e3-baa8-0800200c9a66`

Valid UUIDs are 16 byte numbers represented as

a hexadecimal string in five sub-groups seperated
by a dash. Each group has to consist of a fixed
number of hexadecimal digits:
 | Group | Digits |
 | -----:|:------ |
 |     1 | 8      |
 |     2 | 4      |
 |     3 | 4      |
 |     4 | 4      |
 |     5 | 12     |

@param [Object] value Object to cast. @return [String] Casted object as UUID.

# File lib/acfs/resource/attributes/uuid.rb, line 35
def cast_value(value)
  if value.blank?
    nil
  elsif value.to_s =~ UUID_REGEXP
    value
  else
    raise TypeError.new "Invalid UUID: `#{value}'"
  end
end