Class: Kiba::Extend::Destinations::JsonArray
- Inherits:
-
Object
- Object
- Kiba::Extend::Destinations::JsonArray
show all
- Extended by:
- 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
as_source_class, is_destination?, special_options
#default_args, #default_file_options, #labeled_options, #options_key, #path_key, #requires_path?
Constructor Details
#initialize(filename:) ⇒ JsonArray
Returns a new instance of JsonArray.
43
44
45
46
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 43
def initialize(filename:)
@json = []
@file = File.open(filename, "w")
end
|
Class Method Details
.as_source_class ⇒ Object
17
18
19
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 17
def as_source_class
nil
end
|
.default_file_options ⇒ Object
21
22
23
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 21
def default_file_options
nil
end
|
.options_key ⇒ Object
25
26
27
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 25
def options_key
nil
end
|
.path_key ⇒ Object
29
30
31
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 29
def path_key
:filename
end
|
.requires_path? ⇒ Boolean
33
34
35
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 33
def requires_path?
true
end
|
.special_options ⇒ Object
37
38
39
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 37
def special_options
[]
end
|
Instance Method Details
#close ⇒ Object
54
55
56
57
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 54
def close
@file << @json.to_json
@file.close
end
|
#write(row) ⇒ Object
49
50
51
|
# File 'lib/kiba/extend/destinations/json_array.rb', line 49
def write(row)
@json << row
end
|