Class: Net::SSH::Script::Command
- Inherits:
-
Object
- Object
- Net::SSH::Script::Command
- Defined in:
- lib/net/ssh/script/command.rb
Overview
Net::SSH::Connection::Session wrapper to capture status/stdout/stderr produced by a command.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #done? ⇒ Boolean
-
#initialize(command_string) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #run(ssh) ⇒ Object
- #status ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(command_string) ⇒ Command
Returns a new instance of Command.
15 16 17 18 19 |
# File 'lib/net/ssh/script/command.rb', line 15 def initialize(command_string) @_cmd = command_string @_done = @_success = false @output = @error = '' end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
9 10 11 |
# File 'lib/net/ssh/script/command.rb', line 9 def error @error end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
9 10 11 |
# File 'lib/net/ssh/script/command.rb', line 9 def output @output end |
Class Method Details
.[](command) ⇒ Object
11 12 13 |
# File 'lib/net/ssh/script/command.rb', line 11 def self.[](command) new command end |
Instance Method Details
#done? ⇒ Boolean
33 34 35 |
# File 'lib/net/ssh/script/command.rb', line 33 def done? @_done end |
#inspect ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/net/ssh/script/command.rb', line 37 def inspect case status when :ok "#{status}: #{@_cmd}\nOutput:\n#{@output}\n" when :error "#{status}: #{@_cmd}\nError:\n#{@error}\n" else "#{status}: #{@_cmd}" end end |
#run(ssh) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/net/ssh/script/command.rb', line 21 def run(ssh) channel = ssh.open_channel do |ch| # In case when we want rerun a command @_done = @_success = false exec_command @_cmd, ch end channel.wait ok? end |
#status ⇒ Object
48 49 50 51 52 53 |
# File 'lib/net/ssh/script/command.rb', line 48 def status return :pending unless done? return :failed unless @_success return :error unless @error.empty? :ok end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/net/ssh/script/command.rb', line 55 def to_s @_cmd end |