Class: Acfs::Resource::Attributes::UUID
- Defined in:
- lib/acfs/resource/attributes/uuid.rb
Overview
UUID attribute type. Use it in your model as an attribute type:
Constant Summary collapse
- UUID_REGEXP =
/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}/i
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#cast_value(value) ⇒ String
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.
Methods inherited from Base
#cast, #default_value, #initialize
Constructor Details
This class inherits a constructor from Acfs::Resource::Attributes::Base
Instance Method Details
#cast_value(value) ⇒ String
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 |
35 36 37 38 39 40 41 42 43 |
# File 'lib/acfs/resource/attributes/uuid.rb', line 35 def cast_value(value) if value.blank? nil elsif UUID_REGEXP.match?(value.to_s) value else raise TypeError.new "Invalid UUID: `#{value}'" end end |