We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ad62dd0 commit cda7483Copy full SHA for cda7483
1 file changed
lib/kiba/extend/destinations/json_array.rb
@@ -32,23 +32,31 @@ def initialize(filename:)
32
@filename = filename
33
ensure_dir
34
@json = []
35
- @file = File.open(filename, "w")
+ end
36
+
37
+ # @return [Array<Symbol>]
38
+ def fields
39
+ return [] unless File.exist?(filename)
40
41
+ JSON.parse(File.read(filename))
42
+ .map(&:keys)
43
+ .flatten
44
+ .uniq
45
end
46
47
# @private
48
def write(row)
- @json << row
49
+ json << row
50
51
52
53
def close
- @file << @json.to_json
- @file.close
54
+ File.open(filename, "w") { |f| f << json.to_json }
55
56
57
private
58
- attr_reader :filename
59
+ attr_reader :filename, :json
60
61
62
0 commit comments