Class: Kitsune::Kit::Reporters::Json
- Defined in:
- lib/kitsune/kit/reporters/json.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
Instance Method Summary collapse
- #flush(result: nil, command: nil, environment: nil) ⇒ Object
- #handle(event) ⇒ Object
-
#initialize(output: $stdout, secret_filter: SecretFilter.new) ⇒ Json
constructor
A new instance of Json.
Constructor Details
#initialize(output: $stdout, secret_filter: SecretFilter.new) ⇒ Json
Returns a new instance of Json.
12 13 14 15 16 17 |
# File 'lib/kitsune/kit/reporters/json.rb', line 12 def initialize(output: $stdout, secret_filter: SecretFilter.new) super() @output = output @secret_filter = secret_filter @events = [] end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
10 11 12 |
# File 'lib/kitsune/kit/reporters/json.rb', line 10 def events @events end |
Instance Method Details
#flush(result: nil, command: nil, environment: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kitsune/kit/reporters/json.rb', line 23 def flush(result: nil, command: nil, environment: nil) started = event("run_started", reverse: true) finished = event("run_finished", reverse: true) payload = { schema_version: 1, command: command || started&.dig(:data, :command), environment: environment || started&.dig(:data, :environment), run_id: started&.dig(:run_id) || result&.&.dig(:run_id), status: (result&.status || status_from_events).to_s, duration_ms: finished&.dig(:data, :duration_ms), result: @secret_filter.filter(serialize(result&.value)), warnings: @secret_filter.filter(result&.warnings || []), events: @events } @output.puts(::JSON.generate(payload)) payload end |
#handle(event) ⇒ Object
19 20 21 |
# File 'lib/kitsune/kit/reporters/json.rb', line 19 def handle(event) @events << @secret_filter.filter(event.to_h) end |