Class: ActiveRecord::KSUID::Type Private
- Inherits:
-
Type::String
- Object
- Type::String
- ActiveRecord::KSUID::Type
- Defined in:
- lib/active_record/ksuid/type.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A string-serialized KSUID for storage within an ActiveRecord database
Instance Method Summary collapse
-
#cast(value) ⇒ KSUID::Type
private
Casts a value from user input into a KSUID.
-
#deserialize(value) ⇒ KSUID::Type
private
Converts a value from database input to a KSUID.
-
#serialize(value) ⇒ String?
private
Casts the value from a KSUID into a database-understandable format.
Instance Method Details
#cast(value) ⇒ KSUID::Type
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Casts a value from user input into a KSUID
Type casting happens via the attribute setter and can take input from many places, including:
1. The Rails form builder
2. Directly from the attribute setter
3. From the model initializer
30 31 32 |
# File 'lib/active_record/ksuid/type.rb', line 30 def cast(value) ::KSUID.call(value) end |
#deserialize(value) ⇒ KSUID::Type
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a value from database input to a KSUID
38 39 40 41 42 |
# File 'lib/active_record/ksuid/type.rb', line 38 def deserialize(value) return unless value ::KSUID.from_base62(value) end |
#serialize(value) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Casts the value from a KSUID into a database-understandable format
48 49 50 51 52 |
# File 'lib/active_record/ksuid/type.rb', line 48 def serialize(value) return unless value ::KSUID.call(value).to_s end |