class Bixby::CommandResponse
Constants
- SUCCESS
- UNKNOWN_FAILURE
Attributes
status[RW]
stderr[RW]
stdout[RW]
Public Class Methods
from_json_response(res)
click to toggle source
Create a new CommandResponse
from the given JsonResponse
@param [JsonResponse] res
@return [CommandResponse]
# File lib/bixby-common/command_response.rb, line 17 def self.from_json_response(res) cr = CommandResponse.new(res.data) if res.fail? then if !(res.message.nil? || res.message.empty?) then cr.status ||= UNKNOWN_FAILURE cr.stderr ||= res.message else cr.status ||= UNKNOWN_FAILURE end end return cr end
new(params = nil)
click to toggle source
# File lib/bixby-common/command_response.rb, line 37 def initialize(params = nil) if params.kind_of? Hash then params.each{ |k,v| self.send("#{k}=", v) if self.respond_to? "#{k}=" } elsif params.class.to_s == "Mixlib::ShellOut" then @status = params.exitstatus @stdout = params.stdout @stderr = params.stderr end end
Public Instance Methods
decode()
click to toggle source
# File lib/bixby-common/command_response.rb, line 66 def decode # :nocov: MultiJson.load(@stdout) end
decode_stderr()
click to toggle source
# File lib/bixby-common/command_response.rb, line 70 def decode_stderr # :nocov: MultiJson.load(@stderr) end
fail?()
click to toggle source
# File lib/bixby-common/command_response.rb, line 52 def fail? not success? end
Also aliased as: error?
raise!()
click to toggle source
# File lib/bixby-common/command_response.rb, line 57 def raise! if fail? then msg = stdout || "" msg += "\n" if !(stdout.nil? or stdout.empty?) msg += stderr || "" raise CommandException.new(msg, msg) end end
success?()
click to toggle source
# File lib/bixby-common/command_response.rb, line 48 def success? @status && @status.to_i == SUCCESS end
to_json_response()
click to toggle source
Create a JsonResponse
from this CommandResponse
@return [JsonResponse]
# File lib/bixby-common/command_response.rb, line 33 def to_json_response return JsonResponse.new((success?() ? "success" : "fail"), nil, self.to_hash) end
to_s()
click to toggle source
Convert object to String, useful for debugging
@return [String]
# File lib/bixby-common/command_response.rb, line 77 def to_s # :nocov: s = [] s << "CommandResponse:#{self.object_id}" s << " status: #{self.status}" s << " stdout: " + Debug.pretty_str(stdout) s << " stderr: " + Debug.pretty_str(stderr) s.join("\n") end