Class: SwarmClusterCliOpe::ShellCommandResponse
- Inherits:
-
Object
- Object
- SwarmClusterCliOpe::ShellCommandResponse
- Extended by:
- Forwardable
- Includes:
- LoggerConcern
- Defined in:
- lib/swarm_cluster_cli_ope/shell_command_response.rb
Overview
Identifica una risposta dalla shell
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#failed? ⇒ Boolean
Controlla se il valore di status è diverso da 0.
-
#initialize(result) ⇒ ShellCommandResponse
constructor
A new instance of ShellCommandResponse.
-
#result(object_class: OpenStruct, single: false) ⇒ Array<object_class>, Object
## # Ritorna una versione stampabile del risultato def to_s raw_result end.
- #single_obj(object_class: OpenStruct) ⇒ Object
-
#stderr ⇒ Object
Ritorna l’errore della shell.
-
#success? ⇒ TrueClass, FalseClass
Inverso di :failed?.
Methods included from LoggerConcern
Constructor Details
#initialize(result) ⇒ ShellCommandResponse
Returns a new instance of ShellCommandResponse.
18 19 20 |
# File 'lib/swarm_cluster_cli_ope/shell_command_response.rb', line 18 def initialize(result) @raw_result = result end |
Instance Attribute Details
#raw_result ⇒ String
11 12 13 |
# File 'lib/swarm_cluster_cli_ope/shell_command_response.rb', line 11 def raw_result @raw_result end |
Instance Method Details
#failed? ⇒ Boolean
Controlla se il valore di status è diverso da 0
56 57 58 |
# 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) ⇒ Array<object_class>, Object
## # 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
32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
45 46 47 |
# 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 ⇒ Object
Ritorna l’errore della shell
69 70 71 |
# File 'lib/swarm_cluster_cli_ope/shell_command_response.rb', line 69 def stderr raw_result[:stderr] end |
#success? ⇒ TrueClass, FalseClass
Inverso di :failed?
63 64 65 |
# File 'lib/swarm_cluster_cli_ope/shell_command_response.rb', line 63 def success? !failed? end |