Class: Bolt::Outputter::JSON

Inherits:
Bolt::Outputter show all
Defined in:
lib/bolt/outputter/json.rb

Instance Method Summary collapse

Methods inherited from Bolt::Outputter

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


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


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


65
# File 'lib/bolt/outputter/json.rb', line 65

def print_message(message); end


49
50
51
# File 'lib/bolt/outputter/json.rb', line 49

def print_plan_info(plan)
  @stream.puts plan.to_json
end


53
54
55
56
# File 'lib/bolt/outputter/json.rb', line 53

def print_plan_result(result)
  # Ruby JSON patches most objects to have a to_json method.
  @stream.puts result.to_json
end


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


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


40
41
42
# File 'lib/bolt/outputter/json.rb', line 40

def print_table(results)
  @stream.puts results.to_json
end


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