Class: Utils::SshTunnelSpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/ssh_tunnel_specification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec_string) ⇒ SshTunnelSpecification

Initializes a new SshTunnelSpecification instance by parsing the provided specification string.

This method takes a specification string and extracts local and remote address/port combinations to configure the SSH tunnel parameters. The specification can take various formats including port-only specifications, localhost mappings, and full address:port combinations.

tunnel configuration

Parameters:

  • spec_string (String)

    the specification string defining the SSH



13
14
15
# File 'lib/utils/ssh_tunnel_specification.rb', line 13

def initialize(spec_string)
  interpret_spec(spec_string)
end

Instance Attribute Details

#local_addrString? (readonly)

Returns the local address component of the SSH tunnel specification.

Returns:

  • (String, nil)

    the local address used for the SSH tunnel connection



20
21
22
# File 'lib/utils/ssh_tunnel_specification.rb', line 20

def local_addr
  @local_addr
end

#local_portInteger? (readonly)

Returns the local port component of the SSH tunnel specification.

Returns:

  • (Integer, nil)

    the local port number used for the SSH tunnel connection



25
26
27
# File 'lib/utils/ssh_tunnel_specification.rb', line 25

def local_port
  @local_port
end

#remote_addrString? (readonly)

Returns the remote address component of the SSH tunnel specification.

Returns:

  • (String, nil)

    the remote address used for the SSH tunnel connection



30
31
32
# File 'lib/utils/ssh_tunnel_specification.rb', line 30

def remote_addr
  @remote_addr
end

#remote_portInteger? (readonly)

Returns the remote port component of the SSH tunnel specification.

Returns:

  • (Integer, nil)

    the remote port number used for the SSH tunnel connection



35
36
37
# File 'lib/utils/ssh_tunnel_specification.rb', line 35

def remote_port
  @remote_port
end

Instance Method Details

#to_aArray<String, Integer, String, Integer>

Returns an array representation of the SSH tunnel specification.

This method combines the local and remote address/port components into a four-element array in the order: [local_addr, local_port, remote_addr, remote_port].

Returns:

  • (Array<String, Integer, String, Integer>)

    an array containing the local address, local port, remote address, and remote port values



44
45
46
# File 'lib/utils/ssh_tunnel_specification.rb', line 44

def to_a
  [ local_addr, local_port, remote_addr, remote_port ]
end

#to_sString

Returns a string representation of the SSH tunnel specification.

This method combines the local address, local port, remote address, and remote port components into a single colon-separated string format.

Returns:

  • (String)

    a colon-separated string containing the tunnel specification in the format “local_addr:local_port:remote_addr:remote_port”



71
72
73
# File 'lib/utils/ssh_tunnel_specification.rb', line 71

def to_s
  to_a * ':'
end

#valid?String?

Checks if all components of the SSH tunnel specification are present and valid.

This method verifies that all address and port components of the tunnel configuration have been set. If all components are present, it returns the string representation of the specification; otherwise, it returns nil.

Returns:

  • (String, nil)

    the string representation of the specification if all components are present, otherwise nil



58
59
60
61
62
# File 'lib/utils/ssh_tunnel_specification.rb', line 58

def valid?
  if to_a.all?
    to_s
  end
end