class Proxy::OpenBolt::Result

Attributes

command[R]
log[R]
message[R]
schema[R]
status[R]
value[R]

Public Class Methods

new(command, stdout, stderr, exitcode) click to toggle source

This class will take the raw stdout, stderr, status.exitcode objects from a OpenBolt CLI invocation, and parse them accordingly. This should only be used with the –format json flag passed to the OpenBolt CLI, as that changes what data gets put on stdout and stderr.

The “exception” parameter is to be able to handle an unexpected exception, and should generally not be used except where it is right now.

# File lib/smart_proxy_openbolt/result.rb, line 33
def initialize(command, stdout, stderr, exitcode)
  @schema = 1
  @command = command
  if exitcode > 1
    @message = "Command unexpectedly exited with code #{exitcode}"
    @status = :exception
    @value = "stderr:\n#{stderr}\nstdout:\n#{stdout}"
  elsif exitcode == 1 && !stdout.start_with?('{')
    @value = stdout
    @status = :failure
    @log = stderr
  else
    begin
      @value = JSON.parse(stdout)
      @status = exitcode == 0 ? :success : :failure
      @log = stderr
    rescue JSON::ParserError => e
      @status = :exception
      @message = e.message
      @value = e.inspect
      @log = stderr
    end
  end
end

Public Instance Methods

to_json(*args) click to toggle source
# File lib/smart_proxy_openbolt/result.rb, line 58
def to_json(*args)
  {
    'command' => @command,
    'status'  => @status,
    'value'   => @value,
    'log'     => @log,
    'message' => @message,
    'schema'  => @schema,
  }.to_json(*args)
end