Class: Micdrop::Ext::JsonLines::JsonLinesSink

Inherits:
Object
  • Object
show all
Defined in:
lib/micdrop/ext/json_lines.rb

Overview

Output data in JSON-Lines (ND-JSON) format

Instance Method Summary collapse

Constructor Details

#initialize(file, close: true) ⇒ JsonLinesSink

Returns a new instance of JsonLinesSink.



38
39
40
41
# File 'lib/micdrop/ext/json_lines.rb', line 38

def initialize(file, close: true)
  @file = file
  @close = close
end

Instance Method Details

#<<(item) ⇒ Object



43
44
45
46
# File 'lib/micdrop/ext/json_lines.rb', line 43

def <<(item)
  JSON.dump(item, @file)
  @file << "\n"
end

#closeObject



48
49
50
# File 'lib/micdrop/ext/json_lines.rb', line 48

def close
  @file.close if @close
end