Class: RHC::Commands::ForwardingSpec

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Helpers
Defined in:
lib/rhc/commands/port_forward.rb

Constant Summary

Constants included from Helpers

Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#agree, #certificate_file, #client_from_options, #collect_env_vars, #color, #confirm_action, #date, #datetime_rfc3339, #debug, #debug?, #debug_error, #decode_json, #deprecated, #deprecated_command, #disable_deprecated?, #distance_of_time_in_words, #env_var_regex_pattern, #error, #exec, #host_exists?, #hosts_file_contains?, #human_size, #info, #interactive?, #jruby?, #mac?, #openshift_online_server?, #openshift_rest_endpoint, #openshift_server, #openshift_url, #pluralize, #results, #role_name, #run_with_tee, #ssh_string, #ssh_string_parts, #ssl_options, #success, #system_path, #table_heading, #to_host, #to_uri, #token_for_user, #unix?, #user_agent, #warn, #windows?, #with_tolerant_encoding

Methods included from OutputHelpers

#default_display_env_var, #display_app, #display_app_configurations, #display_authorization, #display_cart, #display_cart_storage_info, #display_cart_storage_list, #display_deployment, #display_deployment_list, #display_domain, #display_env_var_list, #display_key, #display_team, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message

Constructor Details

#initialize(service, remote_host, port_to, port_from = nil) ⇒ ForwardingSpec

Returns a new instance of ForwardingSpec.



12
13
14
15
16
17
18
19
# 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

Instance Attribute Details

#bound=(value) ⇒ Object (writeonly)

Sets the attribute bound

Parameters:

  • value

    the value to set the attribute bound to.



10
11
12
# File 'lib/rhc/commands/port_forward.rb', line 10

def bound=(value)
  @bound = value
end

#host_fromObject (readonly)

Returns the value of attribute host_from.



9
10
11
# File 'lib/rhc/commands/port_forward.rb', line 9

def host_from
  @host_from
end

#port_fromObject

class to represent how SSH port forwarding should be performed



8
9
10
# File 'lib/rhc/commands/port_forward.rb', line 8

def port_from
  @port_from
end

#port_toObject (readonly)

Returns the value of attribute port_to.



9
10
11
# File 'lib/rhc/commands/port_forward.rb', line 9

def port_to
  @port_to
end

#remote_hostObject (readonly)

Returns the value of attribute remote_host.



9
10
11
# File 'lib/rhc/commands/port_forward.rb', line 9

def remote_host
  @remote_host
end

#serviceObject (readonly)

Returns the value of attribute service.



9
10
11
# File 'lib/rhc/commands/port_forward.rb', line 9

def service
  @service
end

Instance Method Details

#<=>(other) ⇒ Object

:nocov: These are for sorting. No need to test for coverage.



36
37
38
39
40
41
42
43
44
# 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

#bound?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rhc/commands/port_forward.rb', line 31

def bound?
  @bound
end

#to_cmd_argObject



21
22
23
24
# 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

#to_fwd_argsObject



26
27
28
29
# 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