Class: Billy::Proxy
- Inherits:
-
Object
- Object
- Billy::Proxy
- Defined in:
- lib/billy/proxy.rb
Instance Method Summary collapse
- #call(method, url, headers, body) ⇒ Object
- #host ⇒ Object
-
#initialize ⇒ Proxy
constructor
A new instance of Proxy.
- #port ⇒ Object
- #reset ⇒ Object
- #start(threaded = true) ⇒ Object
- #stub(url, options = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize ⇒ Proxy
Returns a new instance of Proxy.
7 8 9 |
# File 'lib/billy/proxy.rb', line 7 def initialize reset end |
Instance Method Details
#call(method, url, headers, body) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/billy/proxy.rb', line 32 def call(method, url, headers, body) stub = find_stub(method, url) unless stub.nil? query_string = URI.parse(url).query || "" params = CGI.parse(query_string) stub.call(params, headers, body) end end |
#host ⇒ Object
24 25 26 |
# File 'lib/billy/proxy.rb', line 24 def host 'localhost' end |
#port ⇒ Object
28 29 30 |
# File 'lib/billy/proxy.rb', line 28 def port Socket.unpack_sockaddr_in(EM.get_sockname(@signature)).first end |
#reset ⇒ Object
47 48 49 |
# File 'lib/billy/proxy.rb', line 47 def reset @stubs = [] end |
#start(threaded = true) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/billy/proxy.rb', line 11 def start(threaded = true) if threaded Thread.new { main_loop } sleep(0.01) while @signature.nil? else main_loop end end |
#stub(url, options = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/billy/proxy.rb', line 41 def stub(url, = {}) ret = ProxyRequestStub.new(url, ) @stubs << ret ret end |
#url ⇒ Object
20 21 22 |
# File 'lib/billy/proxy.rb', line 20 def url "http://#{host}:#{port}" end |