Class: Tempest::Output::JsonWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest/output/json_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ JsonWriter

Returns a new instance of JsonWriter.



6
7
8
# File 'lib/tempest/output/json_writer.rb', line 6

def initialize(io)
  @io = io
end

Instance Method Details

#write_error(message, code:, details: nil) ⇒ Object



14
15
16
17
18
# File 'lib/tempest/output/json_writer.rb', line 14

def write_error(message, code:, details: nil)
  payload = { "error" => message, "code" => code }
  payload["details"] = details unless details.nil?
  @io.puts JSON.generate(payload)
end

#write_posts(views) ⇒ Object



10
11
12
# File 'lib/tempest/output/json_writer.rb', line 10

def write_posts(views)
  views.each { |v| @io.puts JSON.generate(v) }
end

#write_raw(payload) ⇒ Object



20
21
22
# File 'lib/tempest/output/json_writer.rb', line 20

def write_raw(payload)
  @io.puts JSON.pretty_generate(payload)
end