Class: Chronicle::ETL::JSONLoader
Instance Attribute Summary
#connector_registration
Instance Method Summary
collapse
#create_stdout_temp_file, #output_to_stdout?, #write_to_stdout, #write_to_stdout_from_temp_file
#register_connector
#force_utf8
included
Constructor Details
#initialize(*args) ⇒ JSONLoader
Returns a new instance of JSONLoader.
21
22
23
24
|
# File 'lib/chronicle/etl/loaders/json_loader.rb', line 21
def initialize(*args)
super
@first_line = true
end
|
Instance Method Details
#finish ⇒ Object
67
68
69
70
71
72
73
74
|
# File 'lib/chronicle/etl/loaders/json_loader.rb', line 67
def finish
@output_file.puts("\n]") unless @config.line_separated
write_to_stdout_from_temp_file(@output_file) if output_to_stdout?
@output_file.close
end
|
#load(record) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/chronicle/etl/loaders/json_loader.rb', line 37
def load(record)
serialized = record.to_h
encoded = deeply_force_utf8(serialized)
line = encoded.to_json
if @config.line_separated
line = "#{line}\n"
else
line = ",\n#{line}" unless @first_line
end
@output_file.write(line)
@first_line = false
end
|
#start ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/chronicle/etl/loaders/json_loader.rb', line 26
def start
@output_file =
if output_to_stdout?
create_stdout_temp_file
else
File.open(@config.output, 'w+')
end
@output_file.puts("[\n") unless @config.line_separated
end
|