Sha256: 1f6ac4eb45092ede78dc8816e44d7b9124c69d95bb3429823a938e85ebc7bb73

Contents?: true

Size: 1.04 KB

Versions: 86

Compression:

Stored size: 1.04 KB

Contents

module Utils
  class SshTunnelSpecification
    def initialize(spec_string)
      interpret_spec(spec_string)
    end

    attr_reader :local_addr

    attr_reader :local_port

    attr_reader :remote_addr

    attr_reader :remote_port

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

    def valid?
      if to_a.all?
        to_s
      end
    end

    def to_s
      to_a * ':'
    end

    private

    def interpret_spec(spec_string)
      @local_addr, @local_port, @remote_addr, @remote_port =
        case spec_string
        when /\A(\d+)\z/
          [ 'localhost', $1.to_i, 'localhost', $1.to_i ]
        when /\A(\[[^\]]+\]|[^:]+):(\d+)\z/
          [ 'localhost', $2.to_i, $1, $2.to_i ]
        when /\A(\d+):(\[[^\]]+\]|[^:]+):(\d+)\z/
          [ 'localhost', $1.to_i, $2, $3.to_i ]
        when /\A(\[[^\]]+\]|[^:]+):(\[[^\]]+\]|[^:]+):(\d+)\z/
          [ $1, $3.to_i, $2, $3.to_i ]
        when /\A(\[[^\]]+\]|[^:]+):(\d+):(\[[^\]]+\]|[^:]+):(\d+)\z/
          [ $1, $2.to_i, $3, $4.to_i ]
        end
    end
  end
end

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
utils-0.60.1 lib/utils/ssh_tunnel_specification.rb
utils-0.60.0 lib/utils/ssh_tunnel_specification.rb
utils-0.59.2 lib/utils/ssh_tunnel_specification.rb
utils-0.59.1 lib/utils/ssh_tunnel_specification.rb
utils-0.59.0 lib/utils/ssh_tunnel_specification.rb
utils-0.58.0 lib/utils/ssh_tunnel_specification.rb
utils-0.57.1 lib/utils/ssh_tunnel_specification.rb
utils-0.57.0 lib/utils/ssh_tunnel_specification.rb
utils-0.56.1 lib/utils/ssh_tunnel_specification.rb
utils-0.56.0 lib/utils/ssh_tunnel_specification.rb
utils-0.55.0 lib/utils/ssh_tunnel_specification.rb
utils-0.54.1 lib/utils/ssh_tunnel_specification.rb
utils-0.54.0 lib/utils/ssh_tunnel_specification.rb
utils-0.53.1 lib/utils/ssh_tunnel_specification.rb
utils-0.53.0 lib/utils/ssh_tunnel_specification.rb
utils-0.52.1 lib/utils/ssh_tunnel_specification.rb
utils-0.52.0 lib/utils/ssh_tunnel_specification.rb
utils-0.51.1 lib/utils/ssh_tunnel_specification.rb
utils-0.51.0 lib/utils/ssh_tunnel_specification.rb
utils-0.50.0 lib/utils/ssh_tunnel_specification.rb