Sha256: d77d47098fdcb323559419e4f5431690a85678b6d062f1dae54ede9164b83402

Contents?: true

Size: 887 Bytes

Versions: 15

Compression:

Stored size: 887 Bytes

Contents

module Traject
  # Uses #put method from the traject writer API to just accumulate
  # output_hash'es in an array. Useful for testing, or for simple programmatic
  # use.
  #
  # Useful with process_with:
  #
  #     indexer.process_with(source_array, ArrayWriter.new).values
  #       # => array of output_hash's
  #
  # Recommend against using it with huge number of records, as it will
  # of course store them all in memory.
  #
  # Uses Concurrent::Arrays internally, so should be safe for use as writer
  # in concurrency scenarios.
  class ArrayWriter
    attr_reader :values, :contexts

    def initialize(_settings = nil)
      @values = Concurrent::Array.new
      @contexts = Concurrent::Array.new
    end

    def put(context)
      contexts << context
      values << context.output_hash
    end

    def clear!
      @contexts.delete
      @values.delete
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
traject-3.8.3 lib/traject/array_writer.rb
traject-3.8.2 lib/traject/array_writer.rb
traject-3.8.1 lib/traject/array_writer.rb
traject-3.8.0 lib/traject/array_writer.rb
traject-3.7.0 lib/traject/array_writer.rb
traject-3.6.0 lib/traject/array_writer.rb
traject-3.5.0 lib/traject/array_writer.rb
traject-3.4.0 lib/traject/array_writer.rb
traject-3.3.0 lib/traject/array_writer.rb
traject-3.2.0 lib/traject/array_writer.rb
traject-3.1.0 lib/traject/array_writer.rb
traject-3.1.0.rc1 lib/traject/array_writer.rb
traject-3.0.0 lib/traject/array_writer.rb
traject-3.0.0.alpha.2 lib/traject/array_writer.rb
traject-3.0.0.alpha.1 lib/traject/array_writer.rb