Sha256: 1509720a90b466af36fadcc398c529039e47665d3479399825c3fa01d6843b71
Contents?: true
Size: 1.11 KB
Versions: 62
Compression:
Stored size: 1.11 KB
Contents
module Workarea module Elasticsearch module Serializer class << self def serialize(model) serialized = if model.is_a?(Mongoid::Document) serialize_mongoid(model) else serialize_object(model) end { 'model_class' => model.class.name, 'model' => serialized } end def deserialize(source) klass = source['model_class'].constantize if klass < Mongoid::Document deserialize_mongoid(klass, source['model']) else deserialize_object(source['model']) end end def serialize_mongoid(model) serialize_object(model.as_document) end def serialize_object(object) Base64.encode64(Marshal.dump(object)) end def deserialize_mongoid(klass, serialized) Mongoid::Factory.from_db(klass, deserialize_object(serialized)) end def deserialize_object(object) Marshal.load(Base64.decode64(object)) end end end end end
Version data entries
62 entries across 62 versions & 1 rubygems