Sha256: 8f31b634571fcb3b7a12eff0fb08cf0dcf1f1fa1d5c8e7c84810c2edec5568ad

Contents?: true

Size: 924 Bytes

Versions: 14

Compression:

Stored size: 924 Bytes

Contents

module Elasticsearch
  module Persistence
    module Repository

      # Provide serialization and deserialization between Ruby objects and Elasticsearch documents
      #
      # Override these methods in your repository class to customize the logic.
      #
      module Serialize

        # Serialize the object for storing it in Elasticsearch
        #
        # In the default implementation, call the `to_hash` method on the passed object.
        #
        def serialize(document)
          document.to_hash
        end

        # Deserialize the document retrieved from Elasticsearch into a Ruby object
        #
        # Use the `klass` property, if defined, otherwise try to get the class from the document's `_type`.
        #
        def deserialize(document)
          _klass = klass || __get_klass_from_type(document['_type'])
          _klass.new document['_source']
        end
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
elasticsearch-persistence-5.1.0 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-5.0.2 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-2.0.1 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-5.0.1 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-2.0.0 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-5.0.0 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.9 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.8 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.7 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.6 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.5 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.4 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.1.3 lib/elasticsearch/persistence/repository/serialize.rb
elasticsearch-persistence-0.0.1 lib/elasticsearch/persistence/repository/serialize.rb