class Dizby::AbstractTunnel

Attributes

local_port[R]
remote_port[R]

Public Class Methods

new(server, strategy, user, host, **options) click to toggle source
# File lib/dizby/tunnel/abstract.rb, line 11
def initialize(server, strategy, user, host, **options)
  @server = server
  ssh_config = options[:ssh] || @server.config[:ssh] || {}
  @config = [host, user, ssh_config]
  @strategy = strategy

  open_ssh_tunnel
end

Public Instance Methods

close() click to toggle source
# File lib/dizby/tunnel/abstract.rb, line 53
def close
  @thread.join if @thread && @thread.alive?
end
get_and_write_ports(ssh, output) click to toggle source
# File lib/dizby/tunnel/abstract.rb, line 33
def get_and_write_ports(ssh, output)
  @strategy.write(ssh, output)
end
loop_ssh(ssh, output) click to toggle source

wait(ssh) is not defined in this class

# File lib/dizby/tunnel/abstract.rb, line 21
def loop_ssh(ssh, output)
  get_and_write_ports(ssh, output)
  wait(ssh)
ensure
  output.close
  ssh.close if ssh
end
open_ssh_tunnel() click to toggle source
# File lib/dizby/tunnel/abstract.rb, line 37
def open_ssh_tunnel
  reader, writer = IO.pipe

  @thread =
    Thread.start(Net::SSH.start(*@config)) do |ssh|
      loop_ssh(ssh, writer)
    end

  read_ports(reader)
rescue
  @thread.abort_on_exception = true
  close
ensure
  reader.close
end
read_ports(input) click to toggle source
# File lib/dizby/tunnel/abstract.rb, line 29
def read_ports(input)
  @local_port, @remote_port = @strategy.read(input)
end