Class: PaperTrail::AttributeSerializers::CastAttributeSerializer
- Inherits:
-
Object
- Object
- PaperTrail::AttributeSerializers::CastAttributeSerializer
- Defined in:
- lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb,
lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb
Overview
Uses AR 5’s ‘serialize` and `deserialize`.
Instance Method Summary collapse
- #deserialize(attr, val) ⇒ Object
-
#initialize(klass) ⇒ CastAttributeSerializer
constructor
A new instance of CastAttributeSerializer.
- #serialize(attr, val) ⇒ Object
Constructor Details
#initialize(klass) ⇒ CastAttributeSerializer
Returns a new instance of CastAttributeSerializer.
15 16 17 |
# File 'lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb', line 15 def initialize(klass) @klass = klass end |
Instance Method Details
#deserialize(attr, val) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb', line 41 def deserialize(attr, val) if defined_enums[attr] && val.is_a?(::String) # Because PT 4 used to save the string version of enums to `object_changes` val else AttributeSerializerFactory.for(@klass, attr).deserialize(val) end end |
#serialize(attr, val) ⇒ Object
37 38 39 |
# File 'lib/mongo_trails/attribute_serializers/cast_attribute_serializer.rb', line 37 def serialize(attr, val) AttributeSerializerFactory.for(@klass, attr).serialize(val) end |