Class: Pair::Session::Tunnel

Inherits:
Object
  • Object
show all
Defined in:
lib/pair/session/tunnel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Tunnel

E.g. options: {

"host_port"  => 22,
"host_login" => "bjeanes",
"port"       => 2222,
"bastion" => {
  "host"       => "bastion.pairmill.com",
  "ip_address" => "12.12.12.12",
  "ssh_port"   => 22,
  "host_user"  => "host",
  "join_user"  => "join",
}

}



20
21
22
# File 'lib/pair/session/tunnel.rb', line 20

def initialize(options)
  self.options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



56
57
58
# File 'lib/pair/session/tunnel.rb', line 56

def method_missing(method, *args, &block)
  options[method.to_s] || super(method, *args, &block)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/pair/session/tunnel.rb', line 4

def options
  @options
end

#tunnelObject

Returns the value of attribute tunnel.



4
5
6
# File 'lib/pair/session/tunnel.rb', line 4

def tunnel
  @tunnel
end

Instance Method Details

#closeObject



34
35
36
37
38
39
40
41
# File 'lib/pair/session/tunnel.rb', line 34

def close
  @tunnel_closed ||= begin
    puts "Closing connection..."
    Process.kill("INT", tunnel.pid)
    Process.wait
    true
  end
end

#openObject



24
25
26
27
28
29
30
31
32
# File 'lib/pair/session/tunnel.rb', line 24

def open
  self.tunnel = IO.popen(ssh_command)
  puts "SSH tunnel started (PID = #{tunnel.pid})" if $-d

  if block_given?
    yield
    close
  end
end