Class: NexusSW::LXD::Transport::Mixins::Helpers::ExecuteMixin::ExecuteResult
- Inherits:
-
Object
- Object
- NexusSW::LXD::Transport::Mixins::Helpers::ExecuteMixin::ExecuteResult
- Defined in:
- lib/nexussw/lxd/transport/mixins/helpers/execute.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#exitstatus ⇒ Object
readonly
Returns the value of attribute exitstatus.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #error! ⇒ Object
- #error? ⇒ Boolean
-
#initialize(command, options, exitstatus) ⇒ ExecuteResult
constructor
A new instance of ExecuteResult.
- #stderr ⇒ Object
- #stdout ⇒ Object
Constructor Details
#initialize(command, options, exitstatus) ⇒ ExecuteResult
Returns a new instance of ExecuteResult.
10 11 12 13 14 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 10 def initialize(command, , exitstatus) @command = command @options = || {} @exitstatus = exitstatus end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
16 17 18 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 16 def command @command end |
#exitstatus ⇒ Object (readonly)
Returns the value of attribute exitstatus.
16 17 18 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 16 def exitstatus @exitstatus end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 16 def @options end |
Instance Method Details
#error! ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 26 def error! return self if exitstatus == 0 msg = "Error: '#{command}' failed with exit code #{exitstatus}.\n" # msg += (" while running as '#{username}'.\n" if username) || ".\n" msg += "STDOUT: #{stdout}" if stdout.is_a?(String) && !stdout.empty? msg += "STDERR: #{stderr}" if stderr.is_a?(String) && !stderr.empty? raise ::NexusSW::LXD::RestAPI::Error, msg end |
#error? ⇒ Boolean
35 36 37 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 35 def error? exitstatus != 0 end |
#stderr ⇒ Object
22 23 24 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 22 def stderr [:capture_options][:stderr] if .key? :capture_options end |
#stdout ⇒ Object
18 19 20 |
# File 'lib/nexussw/lxd/transport/mixins/helpers/execute.rb', line 18 def stdout [:capture_options][:stdout] if .key? :capture_options end |