Class: Esse::HashDocument

Inherits:
Document show all
Defined in:
lib/esse/hash_document.rb

Constant Summary collapse

META_KEYS =
%i[_id _type _routing routing].freeze

Constants inherited from Document

Document::MUTATIONS_FALLBACK

Instance Attribute Summary

Attributes inherited from Document

#object, #options

Instance Method Summary collapse

Methods inherited from Document

#doc_header, #document_for_partial_update, #eql?, #ignore_on_delete?, #ignore_on_index?, #inspect, #mutate, #mutated_source, #mutations, #routing?, #to_bulk, #to_h, #type?

Constructor Details

#initialize(object) ⇒ HashDocument

Returns a new instance of HashDocument.



7
8
9
10
# File 'lib/esse/hash_document.rb', line 7

def initialize(object)
  @object = object
  @options = {}
end

Instance Method Details

#idString, Number

Returns the document ID.

Returns:

  • (String, Number)

    the document ID



13
14
15
# File 'lib/esse/hash_document.rb', line 13

def id
  object['_id'] || object[:_id] || object['id'] || object[:id]
end

#metaHash

Returns the document meta.

Returns:

  • (Hash)

    the document meta



28
29
30
# File 'lib/esse/hash_document.rb', line 28

def meta
  {}
end

#routingString?

Returns the document routing.

Returns:

  • (String, nil)

    the document routing



23
24
25
# File 'lib/esse/hash_document.rb', line 23

def routing
  object['_routing'] || object[:_routing] || object['routing'] || object[:routing]
end

#sourceHash

This method is abstract.

Override this method to return the document source

Returns the document source.

Returns:

  • (Hash)

    the document source



34
35
36
# File 'lib/esse/hash_document.rb', line 34

def source
  object.reject { |key, _| META_KEYS.include?(key.to_sym) }
end

#typeString?

Returns the document type.

Returns:

  • (String, nil)

    the document type



18
19
20
# File 'lib/esse/hash_document.rb', line 18

def type
  object['_type'] || object[:_type]
end