Class: Bolt::Outputter::JSON
Instance Method Summary
collapse
for_format, #replace_data_type
Constructor Details
#initialize(stream = $stdout) ⇒ JSON
Returns a new instance of JSON.
4
5
6
7
8
9
|
# File 'lib/bolt/outputter/json.rb', line 4
def initialize(stream = $stdout)
@items_open = false
@object_open = false
@preceding_item = false
super(stream)
end
|
Instance Method Details
#fatal_error(e) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/bolt/outputter/json.rb', line 58
def fatal_error(e)
@stream.puts "],\n" if @items_open
@stream.puts '"_error": ' if @object_open
@stream.puts e.to_json
@stream.puts '}' if @object_open
end
|
#print_event(event) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/bolt/outputter/json.rb', line 18
def print_event(event)
case event[:type]
when :node_result
print_result(event[:result])
end
end
|
#print_head ⇒ Object
11
12
13
14
15
16
|
# File 'lib/bolt/outputter/json.rb', line 11
def print_head
@stream.puts '{ "items": ['
@preceding_item = false
@items_open = true
@object_open = true
end
|
#print_message(message) ⇒ Object
65
|
# File 'lib/bolt/outputter/json.rb', line 65
def print_message(message); end
|
#print_plan_info(plan) ⇒ Object
49
50
51
|
# File 'lib/bolt/outputter/json.rb', line 49
def print_plan_info(plan)
@stream.puts plan.to_json
end
|
#print_plan_result(result) ⇒ Object
53
54
55
56
|
# File 'lib/bolt/outputter/json.rb', line 53
def print_plan_result(result)
@stream.puts result.to_json
end
|
#print_result(result) ⇒ Object
25
26
27
28
29
|
# File 'lib/bolt/outputter/json.rb', line 25
def print_result(result)
@stream.puts ',' if @preceding_item
@stream.puts result.status_hash.to_json
@preceding_item = true
end
|
#print_summary(results, elapsed_time) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/bolt/outputter/json.rb', line 31
def print_summary(results, elapsed_time)
@stream.puts "],\n"
@preceding_item = false
@items_open = false
@stream.puts format('"node_count": %d, "elapsed_time": %d }',
results.size,
elapsed_time)
end
|
#print_table(results) ⇒ Object
40
41
42
|
# File 'lib/bolt/outputter/json.rb', line 40
def print_table(results)
@stream.puts results.to_json
end
|
#print_task_info(task) ⇒ Object
44
45
46
47
|
# File 'lib/bolt/outputter/json.rb', line 44
def print_task_info(task)
replace_data_type(task['parameters'])
@stream.puts task.to_json
end
|