Class: Billy::Proxy

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/billy/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProxy

Returns a new instance of Proxy.



12
13
14
15
# File 'lib/billy/proxy.rb', line 12

def initialize
  @request_handler = Billy::RequestHandler.new
  reset
end

Instance Attribute Details

#request_handlerObject (readonly)

Returns the value of attribute request_handler.



8
9
10
# File 'lib/billy/proxy.rb', line 8

def request_handler
  @request_handler
end

Instance Method Details

#cacheObject



46
47
48
# File 'lib/billy/proxy.rb', line 46

def cache
  Billy::Cache.instance
end

#hostObject



38
39
40
# File 'lib/billy/proxy.rb', line 38

def host
  Billy.config.proxy_host
end

#portObject



42
43
44
# File 'lib/billy/proxy.rb', line 42

def port
  Socket.unpack_sockaddr_in(EM.get_sockname(@signature)).first
end

#start(threaded = true) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/billy/proxy.rb', line 17

def start(threaded = true)
  if threaded
    Thread.new { main_loop }
    sleep(0.01) while (not defined?(@signature)) || @signature.nil?
  else
    main_loop
  end
end

#stopObject



26
27
28
29
30
31
32
# File 'lib/billy/proxy.rb', line 26

def stop
  return if @signature.nil?

  server_port = port
  EM.stop
  wait_for_server_shutdown! server_port
end

#urlObject



34
35
36
# File 'lib/billy/proxy.rb', line 34

def url
  "http://#{host}:#{port}"
end