Class: Yads::SSH

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ SSH

Returns a new instance of SSH.



7
8
9
10
11
12
# File 'lib/yads/ssh.rb', line 7

def initialize(config)
  options = { :forward_agent => config[:forward_agent] }
  options[:port] = config[:port] if config[:port]

  @ssh = Net::SSH.start(config[:host], config[:user], options)
end

Instance Method Details

#closeObject



25
26
27
# File 'lib/yads/ssh.rb', line 25

def close
  @ssh.close
end

#execute(cmd) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/yads/ssh.rb', line 14

def execute(cmd)
  if block_given?
    @ssh.exec(cmd) do |ch, stream, data|
      yield data
    end
    @ssh.loop
  else
    @ssh.exec!(cmd)
  end
end