Class: Devproxy::Connection

Inherits:
Struct
  • Object
show all
Defined in:
lib/devproxy/connection.rb

Direct Known Subclasses

CLI

Constant Summary collapse

MAX_DOTS =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
# File 'lib/devproxy/connection.rb', line 7

def initialize options
  super
  reset_dots!
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



4
5
6
# File 'lib/devproxy/connection.rb', line 4

def options
  @options
end

Instance Method Details

#loop!Object



12
13
14
15
16
17
18
19
# File 'lib/devproxy/connection.rb', line 12

def loop!
  @session.shutdown! if @session
  @session = create_session
  @session.loop! if @session
rescue Errno::ECONNREFUSED
  on_stderr "CONNECTION REFUSED.  Is there anything listening on port #{options.port}?"
  retry
end

#on_closeObject



49
50
51
# File 'lib/devproxy/connection.rb', line 49

def on_close
  stop!
end

#on_connected(proxy) ⇒ Object



25
26
27
# File 'lib/devproxy/connection.rb', line 25

def on_connected(proxy)
  $stdout.puts "Tunneling requests from https://#{proxy}.#{options.app_host} to #{options.listen} port #{options.port}"
end

#on_heartbeat(data) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/devproxy/connection.rb', line 29

def on_heartbeat data
  return unless options.verbose
  $stdout.write "."
  if (@dotno += 1) % MAX_DOTS == 0
    $stdout.write "\n"
  end
end

#on_stderr(data) ⇒ Object



43
44
45
46
47
# File 'lib/devproxy/connection.rb', line 43

def on_stderr data
  $stdout.write("\n") if options.verbose
  $stderr.puts(data)
  reset_dots!
end

#on_stdout(data) ⇒ Object



37
38
39
40
41
# File 'lib/devproxy/connection.rb', line 37

def on_stdout data
  $stdout.write("\n") if options.verbose
  $stdout.puts(data)
  reset_dots!
end

#stop!Object



21
22
23
# File 'lib/devproxy/connection.rb', line 21

def stop!
  @session.stop! if @session
end