Class: Esse::HashDocument
- Defined in:
- lib/esse/hash_document.rb
Constant Summary collapse
- META_KEYS =
%i[_id _type _routing routing].freeze
Constants inherited from Document
Instance Attribute Summary
Attributes inherited from Document
Instance Method Summary collapse
-
#id ⇒ String, Number
The document ID.
-
#initialize(object) ⇒ HashDocument
constructor
A new instance of HashDocument.
-
#meta ⇒ Hash
The document meta.
-
#routing ⇒ String?
The document routing.
-
#source ⇒ Hash
abstract
The document source.
-
#type ⇒ String?
The document type.
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
#id ⇒ String, Number
Returns 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 |
#meta ⇒ Hash
Returns the document meta.
28 29 30 |
# File 'lib/esse/hash_document.rb', line 28 def {} end |
#routing ⇒ String?
Returns 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 |
#source ⇒ Hash
This method is abstract.
Override this method to return the document source
Returns 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 |
#type ⇒ String?
Returns the document type.
18 19 20 |
# File 'lib/esse/hash_document.rb', line 18 def type object['_type'] || object[:_type] end |