Class: Proxy::OpenBolt::Result
- Inherits:
-
Object
- Object
- Proxy::OpenBolt::Result
- Defined in:
- lib/smart_proxy_openbolt/result.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(command, stdout, stderr, exitcode) ⇒ Result
constructor
This class will take the raw stdout, stderr, status.exitcode objects from a OpenBolt CLI invocation, and parse them accordingly.
- #to_json(*args) ⇒ Object
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. @value = e.inspect @log = stderr end end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/smart_proxy_openbolt/result.rb', line 5 def command @command end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
5 6 7 |
# File 'lib/smart_proxy_openbolt/result.rb', line 5 def log @log end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/smart_proxy_openbolt/result.rb', line 5 def @message end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
5 6 7 |
# File 'lib/smart_proxy_openbolt/result.rb', line 5 def schema @schema end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/smart_proxy_openbolt/result.rb', line 5 def status @status end |
#value ⇒ Object (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 |