Sha256: 8463019c0f3ab8df51237276c81afb484cf0a68c28a6782a0917005d65da408d

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Esse
  class Index
    module ObjectDocumentMapper
      # Wrap collection data into serialized batches
      #
      # @param [String, NilClass] repo_name The repository identifier
      # @param [Hash] kwargs The context
      # @return [Enumerator] The enumerator
      # @yield [Array, **context] serialized collection and the optional context from the collection
      def each_serialized_batch(repo_name = nil, **kwargs, &block)
        (repo_name ? [repo(repo_name)] : repo_hash.values).each do |repo|
          repo.each_serialized_batch(**kwargs, &block)
        end
      end

      # Wrap collection data into serialized documents
      #
      # Example:
      #    GeosIndex.documents(id: 1).first
      #
      # @param [String, NilClass] repo_name The repository identifier
      # @return [Enumerator] All serialized entries
      def documents(repo_name = nil, **kwargs)
        Enumerator.new do |yielder|
          each_serialized_batch(repo_name, **kwargs) do |documents, **_collection_kargs|
            documents.each { |document| yielder.yield(document) }
          end
        end
      end
    end

    extend ObjectDocumentMapper
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
esse-0.3.5 lib/esse/index/object_document_mapper.rb
esse-0.3.4 lib/esse/index/object_document_mapper.rb
esse-0.3.3 lib/esse/index/object_document_mapper.rb
esse-0.3.2 lib/esse/index/object_document_mapper.rb
esse-0.3.1 lib/esse/index/object_document_mapper.rb
esse-0.3.0 lib/esse/index/object_document_mapper.rb
esse-0.2.6 lib/esse/index/object_document_mapper.rb
esse-0.2.5 lib/esse/index/object_document_mapper.rb
esse-0.2.4 lib/esse/index/object_document_mapper.rb
esse-0.2.3 lib/esse/index/object_document_mapper.rb