Class: UuidAttribute::Type
- Inherits:
-
ActiveModel::Type::Binary
- Object
- ActiveModel::Type::Binary
- UuidAttribute::Type
- Defined in:
- lib/uuid_attribute/type.rb
Overview
UUID Attribute
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/uuid_attribute/type.rb', line 33 def cast(value) # puts "CAST" return nil if value.nil? # return value if value.is_a?(UUID) value = value.to_s if value.is_a?(ActiveModel::Type::Binary::Data) return Utils.shorten(Utils.normalize(Utils.parse(value))) # super end |
#deserialize(value) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/uuid_attribute/type.rb', line 23 def deserialize(value) # puts "DESERIALIZE" return nil if value.nil? value = value.to_s if value.is_a?(ActiveModel::Type::Binary::Data) # return UUID.new(Utils.normalize(Utils.parse(value))) return Utils.shorten(Utils.normalize(Utils.parse(value))) # ActiveRecord::Type::Binary::Data.new(Utils.raw_bytes(Utils.normalize(Utils.parse(value)))) end |
#serialize(value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/uuid_attribute/type.rb', line 9 def serialize(value) #puts "SERIALIZE" return if value.blank? return value if value.is_a?(ActiveRecord::Type::Binary::Data) binary_data = value binary_data = Utils.raw_bytes(Utils.normalize(Utils.parse(value))) if value.is_a?(String) # binary_data = value.raw if value.is_a?(UUID) ActiveRecord::Type::Binary::Data.new( binary_data ) end |
#type ⇒ Object
5 6 7 |
# File 'lib/uuid_attribute/type.rb', line 5 def type :uuid end |