Class: BulkImports::Common::Extractors::NdjsonExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/bulk_imports/common/extractors/ndjson_extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(relation:) ⇒ NdjsonExtractor

Returns a new instance of NdjsonExtractor.


7
8
9
10
# File 'lib/bulk_imports/common/extractors/ndjson_extractor.rb', line 7

def initialize(relation:)
  @relation = relation
  @tmpdir = Dir.mktmpdir
end

Instance Method Details

#extract(context) ⇒ Object


12
13
14
15
16
17
18
19
# File 'lib/bulk_imports/common/extractors/ndjson_extractor.rb', line 12

def extract(context)
  download_service(context).execute
  decompression_service.execute

  records = ndjson_reader.consume_relation('', relation)

  BulkImports::Pipeline::ExtractedData.new(data: records)
end

#remove_tmpdirObject


21
22
23
# File 'lib/bulk_imports/common/extractors/ndjson_extractor.rb', line 21

def remove_tmpdir
  FileUtils.remove_entry(tmpdir) if Dir.exist?(tmpdir)
end