Class: ActiveRecord::Type::Uuid
- Inherits:
-
Binary
- Object
- Binary
- ActiveRecord::Type::Uuid
- Defined in:
- lib/active_record-mysql-uuid_column/type_class.rb
Defined Under Namespace
Classes: Data
Instance Method Summary collapse
- #assert_valid_value(value) ⇒ Object
-
#cast(value) ⇒ Object
from user input (string) to database.
-
#deserialize(value) ⇒ Object
from database binary(16) to string.
- #serialize(value) ⇒ Object
- #type ⇒ Object
Instance Method Details
#assert_valid_value(value) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_record-mysql-uuid_column/type_class.rb', line 30 def assert_valid_value(value) case value.class when String, ActiveSupport::ToJsonWithActiveSupportEncoder if value.blank? || value.to_s.downcase.gsub(/[^a-f0-9]/, '').size == 32 value else raise SerializationTypeMismatch, "Invalid String uuid '#{value}'" end else raise SerializationTypeMismatch, "Unsupported value object of type #{value.class}." end end |
#cast(value) ⇒ Object
from user input (string) to database
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record-mysql-uuid_column/type_class.rb', line 15 def cast(value) if value.is_a?(Data) value elsif value.is_a?(ActiveSupport::ToJsonWithActiveSupportEncoder) or value.is_a?(String) Data.from_uuid_string(super) else raise ArgumentError, "Unsupported input data of class type #{value.class}" end end |
#deserialize(value) ⇒ Object
from database binary(16) to string
9 10 11 12 |
# File 'lib/active_record-mysql-uuid_column/type_class.rb', line 9 def deserialize(value) return nil if value.nil? Data.from_database(value) end |
#serialize(value) ⇒ Object
26 27 28 |
# File 'lib/active_record-mysql-uuid_column/type_class.rb', line 26 def serialize(value) value end |
#type ⇒ Object
4 5 6 |
# File 'lib/active_record-mysql-uuid_column/type_class.rb', line 4 def type :uuid end |