Class: Net::SSH::SessionCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/session_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, output = nil, exit_code = nil, duration = 0) ⇒ SessionCommand

Initialize a new session command



14
15
16
17
18
19
# File 'lib/net/ssh/session_command.rb', line 14

def initialize(command, output=nil, exit_code=nil, duration=0)
  @command   = command
  @output    = output || ''
  @exit_code = Integer(exit_code) rescue 1 if exit_code != nil
  @duration  = Float(duration)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



4
5
6
# File 'lib/net/ssh/session_command.rb', line 4

def command
  @command
end

#durationObject (readonly)

Returns the value of attribute duration.



4
5
6
# File 'lib/net/ssh/session_command.rb', line 4

def duration
  @duration
end

#exit_codeObject

Returns the value of attribute exit_code.



5
6
7
# File 'lib/net/ssh/session_command.rb', line 5

def exit_code
  @exit_code
end

#finish_timeObject

Returns the value of attribute finish_time.



6
7
8
# File 'lib/net/ssh/session_command.rb', line 6

def finish_time
  @finish_time
end

#outputObject

Returns the value of attribute output.



5
6
7
# File 'lib/net/ssh/session_command.rb', line 5

def output
  @output
end

#start_timeObject

Returns the value of attribute start_time.



6
7
8
# File 'lib/net/ssh/session_command.rb', line 6

def start_time
  @start_time
end

Instance Method Details

#failure?Boolean Also known as: error?

Check if exit code is not successful



29
30
31
# File 'lib/net/ssh/session_command.rb', line 29

def failure?
  exit_code != 0
end

#success?Boolean

Check if exit code is successful



23
24
25
# File 'lib/net/ssh/session_command.rb', line 23

def success?
  exit_code == 0
end

#to_sString

Get command string representation



37
38
39
# File 'lib/net/ssh/session_command.rb', line 37

def to_s
  "[#{command}] => #{exit_code}, #{output.to_s.bytesize} bytes, #{duration} seconds"
end