Class: Indocker::SshSession
- Inherits:
-
Object
- Object
- Indocker::SshSession
- Defined in:
- lib/indocker/ssh_session.rb
Defined Under Namespace
Classes: ExecResult
Constant Summary collapse
- LOCALHOST =
'localhost'.freeze
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #close ⇒ Object
- #exec!(command) ⇒ Object
-
#initialize(host:, user:, port:, logger:) ⇒ SshSession
constructor
A new instance of SshSession.
- #local? ⇒ Boolean
Constructor Details
#initialize(host:, user:, port:, logger:) ⇒ SshSession
Returns a new instance of SshSession.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/indocker/ssh_session.rb', line 24 def initialize(host:, user:, port:, logger:) @host = host @user = user @port = port @logger = logger if host != LOCALHOST require 'net/ssh' @ssh = Net::SSH.start(@host, @user, {port: @port}) end end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
22 23 24 |
# File 'lib/indocker/ssh_session.rb', line 22 def host @host end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
22 23 24 |
# File 'lib/indocker/ssh_session.rb', line 22 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
22 23 24 |
# File 'lib/indocker/ssh_session.rb', line 22 def port @port end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
22 23 24 |
# File 'lib/indocker/ssh_session.rb', line 22 def user @user end |
Instance Method Details
#close ⇒ Object
48 49 50 51 52 |
# File 'lib/indocker/ssh_session.rb', line 48 def close if @ssh @ssh.close end end |
#exec!(command) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/indocker/ssh_session.rb', line 40 def exec!(command) if local? exec_locally!(command) else exec_remotely!(command) end end |
#local? ⇒ Boolean
36 37 38 |
# File 'lib/indocker/ssh_session.rb', line 36 def local? !@ssh end |