Sha256: d2484fd1533b326fa77fe0d10a6466661aa8ff88bafbe51218323337409331e3

Contents?: true

Size: 893 Bytes

Versions: 14

Compression:

Stored size: 893 Bytes

Contents

# frozen_string_literal: true

module Esse
  class HashDocument < Esse::Document
    META_KEYS = %i[_id _type _routing routing].freeze

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

    # @return [String, Number] the document ID
    def id
      object['_id'] || object[:_id] || object['id'] || object[:id]
    end

    # @return [String, nil] the document type
    def type
      object['_type'] || object[:_type]
    end

    # @return [String, nil] the document routing
    def routing
      object['_routing'] || object[:_routing] || object['routing'] || object[:routing]
    end

    # @return [Hash] the document meta
    def meta
      {}
    end

    # @return [Hash] the document source
    # @abstract Override this method to return the document source
    def source
      object.reject { |key, _| META_KEYS.include?(key.to_sym) }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
esse-0.4.0.rc4 lib/esse/hash_document.rb
esse-0.4.0.rc3 lib/esse/hash_document.rb
esse-0.4.0.rc2 lib/esse/hash_document.rb
esse-0.4.0.rc1 lib/esse/hash_document.rb
esse-0.3.5 lib/esse/hash_document.rb
esse-0.3.4 lib/esse/hash_document.rb
esse-0.3.3 lib/esse/hash_document.rb
esse-0.3.2 lib/esse/hash_document.rb
esse-0.3.1 lib/esse/hash_document.rb
esse-0.3.0 lib/esse/hash_document.rb
esse-0.2.6 lib/esse/hash_document.rb
esse-0.2.5 lib/esse/hash_document.rb
esse-0.2.4 lib/esse/hash_document.rb
esse-0.2.3 lib/esse/hash_document.rb