Class: Rvm2::Shell::Runner::Ssh

Inherits:
Object
  • Object
show all
Defined in:
lib/rvm2/shell/runner/ssh.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, user) ⇒ Ssh

Returns a new instance of Ssh.



6
7
8
9
# File 'lib/rvm2/shell/runner/ssh.rb', line 6

def initialize(host, user)
  @host = host
  @user = user
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/rvm2/shell/runner/ssh.rb', line 4

def host
  @host
end

#last_statusObject (readonly)

Returns the value of attribute last_status.



4
5
6
# File 'lib/rvm2/shell/runner/ssh.rb', line 4

def last_status
  @last_status
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/rvm2/shell/runner/ssh.rb', line 4

def user
  @user
end

Instance Method Details

#execute(command) ⇒ Object

TODO: make it run in one session



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rvm2/shell/runner/ssh.rb', line 12

def execute(command)
  @last_status = nil
  ssh.open_channel do |channel|
    channel.request_pty
    channel.exec command do |ch, success|
      channel.on_data do |ch, data|
        yield(data, nil)
      end
      channel.on_extended_data do |ch, type, data|
        yield(nil, data)
      end
      channel.on_request("exit-status") do |ch, data|
        @last_status = data.read_long
      end
    end
    channel.wait
  end
  ssh.loop
  @last_status
end

#sshObject



33
34
35
# File 'lib/rvm2/shell/runner/ssh.rb', line 33

def ssh
  @ssh ||= Net::SSH.start(host, user)
end