Class: Traject::ArrayWriter
- Inherits:
-
Object
- Object
- Traject::ArrayWriter
- Defined in:
- lib/traject/array_writer.rb
Overview
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.
Instance Attribute Summary collapse
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #clear! ⇒ Object
-
#initialize(_settings = nil) ⇒ ArrayWriter
constructor
A new instance of ArrayWriter.
- #put(context) ⇒ Object
Constructor Details
#initialize(_settings = nil) ⇒ ArrayWriter
Returns a new instance of ArrayWriter.
19 20 21 22 |
# File 'lib/traject/array_writer.rb', line 19 def initialize(_settings = nil) @values = Concurrent::Array.new @contexts = Concurrent::Array.new end |
Instance Attribute Details
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
17 18 19 |
# File 'lib/traject/array_writer.rb', line 17 def contexts @contexts end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
17 18 19 |
# File 'lib/traject/array_writer.rb', line 17 def values @values end |
Instance Method Details
#clear! ⇒ Object
29 30 31 32 |
# File 'lib/traject/array_writer.rb', line 29 def clear! @contexts.delete @values.delete end |
#put(context) ⇒ Object
24 25 26 27 |
# File 'lib/traject/array_writer.rb', line 24 def put(context) contexts << context values << context.output_hash end |