Class: Micdrop::Ext::JsonLines::JsonLinesSink
- Inherits:
-
Object
- Object
- Micdrop::Ext::JsonLines::JsonLinesSink
- Defined in:
- lib/micdrop/ext/json_lines.rb
Overview
Output data in JSON-Lines (ND-JSON) format
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #close ⇒ Object
-
#initialize(file, close: true) ⇒ JsonLinesSink
constructor
A new instance of JsonLinesSink.
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 |
#close ⇒ Object
48 49 50 |
# File 'lib/micdrop/ext/json_lines.rb', line 48 def close @file.close if @close end |