class SwarmClusterCliOpe::ShellCommandResponse
Identifica una risposta dalla shell
Attributes
raw_result[RW]
@return [String]
Public Class Methods
new(result)
click to toggle source
@param [Hash] result composto da:
stdout: [String], stderr: [String], pid: [Integer], status: [Process::Status]
# File lib/swarm_cluster_cli_ope/shell_command_response.rb, line 18 def initialize(result) @raw_result = result end
Public Instance Methods
failed?()
click to toggle source
Controlla se il valore di status รจ diverso da 0
# File lib/swarm_cluster_cli_ope/shell_command_response.rb, line 56 def failed? raw_result[:status].exitstatus.to_i != 0 end
result(object_class: OpenStruct, single: false)
click to toggle source
## # Ritorna una versione stampabile del risultato def to_s
raw_result[:stdout]
end
Risultato, essendo sempre composto da una lista di righe in formato json, ritorniamo un array di json @param [Object] object_class @return [Array<object_class>,Object]
# File lib/swarm_cluster_cli_ope/shell_command_response.rb, line 32 def result(object_class: OpenStruct, single: false) #tento prima di estrapolare direttamente da json e sucessivamente come array if single # questo per k8s, dato che abbiamo come risposta un json vero object_class.new(JSON.parse(raw_result[:stdout])) else # questo nel caso siamo in swarm che ci ritorna un array di json raw_result[:stdout].split("\n").collect { |s| object_class.new(JSON.parse(s)) } end end
single_obj(object_class: OpenStruct)
click to toggle source
@param [Class<OpenStruct>] object_class @return [Object]
# File lib/swarm_cluster_cli_ope/shell_command_response.rb, line 45 def single_obj(object_class: OpenStruct) result(object_class: object_class, single: true) end
stderr()
click to toggle source
Ritorna l'errore della shell
# File lib/swarm_cluster_cli_ope/shell_command_response.rb, line 69 def stderr raw_result[:stderr] end
success?()
click to toggle source
Inverso di :failed? @return [TrueClass, FalseClass]
# File lib/swarm_cluster_cli_ope/shell_command_response.rb, line 63 def success? !failed? end