Module: SimpleMapper::Attributes::Types::SimpleUUID
- Defined in:
- lib/simple_mapper/attributes/types.rb
Overview
Provides basic UUID type support derived from the simple_uuid
gem.
Passes nils through unchanged, but otherwise expects to work with instances of SimpleUUID::UUID
or GUID strings. Attributes using this type will store the data simply as a GUID-conforming string as implemented by SimpleUUID::UUID#to_guid. For both decoding and encoding, a GUID string or an actual SimpleUUID::UUID
instance may be provided, but the result is always the corresponding GUID string.
Registered as :simple_uuid
.
Constant Summary collapse
- EXPECTED_CLASS =
::SimpleUUID::UUID
Class Method Summary collapse
-
.decode(value) ⇒ Object
Decode a
SimpleUUID::UUID
instance or GUID string into validated GUID string; strings will be validated bySimpleUUID::UUID
prior to passing through as the result. -
.default ⇒ Object
Returns a new GUID string value.
-
.encode(value) ⇒ Object
Encoded a
SimpleUUID::UUID
instance, or a GUID string, as a GUID string. - .normalize(value) ⇒ Object
Class Method Details
.decode(value) ⇒ Object
Decode a SimpleUUID::UUID
instance or GUID string into validated GUID string; strings will be validated by SimpleUUID::UUID
prior to passing through as the result.
Passes nils through unchanged.
112 113 114 |
# File 'lib/simple_mapper/attributes/types.rb', line 112 def self.decode(value) normalize(value) end |
.default ⇒ Object
Returns a new GUID string value.
121 122 123 |
# File 'lib/simple_mapper/attributes/types.rb', line 121 def self.default EXPECTED_CLASS.new.to_guid end |
.encode(value) ⇒ Object
Encoded a SimpleUUID::UUID
instance, or a GUID string, as a GUID string. GUID strings for value
will be validated by SimpleUUID::UUID
prior to passing through as the result.
Passes nils through unchanged.
103 104 105 |
# File 'lib/simple_mapper/attributes/types.rb', line 103 def self.encode(value) normalize(value) end |
.normalize(value) ⇒ Object
116 117 118 |
# File 'lib/simple_mapper/attributes/types.rb', line 116 def self.normalize(value) value.nil? ? nil : EXPECTED_CLASS.new(value).to_guid end |