Class: PaperTrail::AttributeSerializers::LegacyActiveRecordShim::SerializedAttribute
- Inherits:
-
Object
- Object
- PaperTrail::AttributeSerializers::LegacyActiveRecordShim::SerializedAttribute
- Defined in:
- lib/paper_trail/attribute_serializers/legacy_active_record_shim.rb
Overview
An attribute which requires manual (de)serialization to/from what we get from the database. It is part of our backport (shim) of rails 4.2’s attribute API. See ‘type_for_attribute` below.
Instance Method Summary collapse
-
#initialize(coder) ⇒ SerializedAttribute
constructor
A new instance of SerializedAttribute.
- #type_cast_for_database(value) ⇒ Object
- #type_cast_from_database(data) ⇒ Object
Constructor Details
#initialize(coder) ⇒ SerializedAttribute
Returns a new instance of SerializedAttribute.
23 24 25 |
# File 'lib/paper_trail/attribute_serializers/legacy_active_record_shim.rb', line 23 def initialize(coder) @coder = coder.respond_to?(:dump) ? coder : PaperTrail.serializer end |
Instance Method Details
#type_cast_for_database(value) ⇒ Object
27 28 29 |
# File 'lib/paper_trail/attribute_serializers/legacy_active_record_shim.rb', line 27 def type_cast_for_database(value) @coder.dump(value) end |
#type_cast_from_database(data) ⇒ Object
31 32 33 |
# File 'lib/paper_trail/attribute_serializers/legacy_active_record_shim.rb', line 31 def type_cast_from_database(data) @coder.load(data) end |