class to represent how SSH port forwarding should be performed
# File lib/rhc/commands/port_forward.rb, line 12 def initialize(service, remote_host, port_to, port_from = nil) @service = service @remote_host = remote_host @port_to = port_to @host_from = '127.0.0.1' @port_from = port_from || port_to # match ports if possible @bound = false end
:nocov: These are for sorting. No need to test for coverage.
# File lib/rhc/commands/port_forward.rb, line 36 def <=>(other) if bound? && !other.bound? -1 elsif !bound? && other.bound? 1 else order_by_attrs(other, :service, :remote_host, :port_from) end end
# File lib/rhc/commands/port_forward.rb, line 31 def bound? @bound end
# File lib/rhc/commands/port_forward.rb, line 21 def to_cmd_arg # string to be used in a direct SSH command "-L #{port_from}:#{remote_host}:#{port_to}" end
# File lib/rhc/commands/port_forward.rb, line 26 def to_fwd_args # array of arguments to be passed to Net::SSH::Service::Forward#local [port_from.to_i, remote_host, port_to.to_i] end
# File lib/rhc/commands/port_forward.rb, line 46 def order_by_attrs(other, *attrs) # compare self and "other" by examining their "attrs" in order # attrs should be an array of symbols to which self and "other" # respond when sent. while attribute = attrs.shift do if self.send(attribute) != other.send(attribute) return self.send(attribute) <=> other.send(attribute) end end 0 end