Sha256: e514c65a1a64af0d879f3a2c3b701d53eb74681fcefc025f1a49563853269af7

Contents?: true

Size: 895 Bytes

Versions: 1

Compression:

Stored size: 895 Bytes

Contents

# frozen_string_literal: true

module Esse
  class HashDocument < Esse::Serializer
    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

1 entries across 1 versions & 1 rubygems

Version Path
esse-0.2.2 lib/esse/hash_document.rb