Class: Proxy::OpenBolt::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_proxy_openbolt/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, stdout, stderr, exitcode) ⇒ Result

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.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/smart_proxy_openbolt/result.rb', line 5

def command
  @command
end

#logObject (readonly)

Returns the value of attribute log.



5
6
7
# File 'lib/smart_proxy_openbolt/result.rb', line 5

def log
  @log
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/smart_proxy_openbolt/result.rb', line 5

def message
  @message
end

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/smart_proxy_openbolt/result.rb', line 5

def schema
  @schema
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/smart_proxy_openbolt/result.rb', line 5

def status
  @status
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/smart_proxy_openbolt/result.rb', line 5

def value
  @value
end

Instance Method Details

#to_json(*args) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# 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