Class: Kiba::Extend::Destinations::JsonArray
- Inherits:
-
Object
- Object
- Kiba::Extend::Destinations::JsonArray
show all
- Includes:
- Destinationable
- Defined in:
- lib/kiba/extend/destinations/json_array.rb
Overview
Writes each row as a valid JSON object that is an element in a JSON
array
This is simliar to the idea of, but not technically compliant with,
JSON Lines
Class Method Summary
collapse
Instance Method Summary
collapse
#ensure_dir, included, is_destination?
Constructor Details
#initialize(filename:) ⇒ JsonArray
Returns a new instance of JsonArray.
31
32
33
34
35
36
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 31
def initialize(filename:)
@filename = filename
ensure_dir
@json = []
@file = File.open(filename, "w")
end
|
Class Method Details
.as_source_class ⇒ Object
17
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 17
def as_source_class = nil
|
.default_file_options ⇒ Object
19
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 19
def default_file_options = nil
|
.options_key ⇒ Object
21
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 21
def options_key = nil
|
.path_key ⇒ Object
23
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 23
def path_key = :filename
|
.requires_path? ⇒ Boolean
25
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 25
def requires_path? = true
|
.special_options ⇒ Object
27
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 27
def special_options = []
|
Instance Method Details
#close ⇒ Object
44
45
46
47
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 44
def close
@file << @json.to_json
@file.close
end
|
#write(row) ⇒ Object
39
40
41
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 39
def write(row)
@json << row
end
|