Class: Glossarist::ConceptStore::Serializer
- Inherits:
-
Object
- Object
- Glossarist::ConceptStore::Serializer
- Defined in:
- lib/glossarist/concept_store.rb
Overview
Custom serializer that preserves both uuid and identifier through YAML string storage. ManagedConcept’s key_value mapping writes both uuid and identifier to the same “id” key, so a naive to_hash/from_hash round-trip loses one of them. Storing the YAML string preserves the model exactly, and explicit metadata fields let the store index and query by uuid/identifier without deserializing.
Instance Method Summary collapse
Instance Method Details
#deserialize(data, model_class) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/glossarist/concept_store.rb', line 22 def deserialize(data, model_class) model = model_class.from_yaml(data["_yaml"]) model.assign_uuid(data["_uuid"]) if data["_uuid"] model.identifier = data["_identifier"] if data["_identifier"] model end |
#serialize(model) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/glossarist/concept_store.rb', line 14 def serialize(model) { "_yaml" => model.to_yaml, "_uuid" => model.uuid, "_identifier" => model.identifier, } end |