Class: Billy::RequestHandler
- Inherits:
-
Object
- Object
- Billy::RequestHandler
- Extended by:
- Forwardable
- Includes:
- Handler
- Defined in:
- lib/billy/handlers/request_handler.rb
Instance Method Summary collapse
- #handle_request(method, url, headers, body) ⇒ Object
- #handlers ⇒ Object
- #handles_request?(method, url, headers, body) ⇒ Boolean
- #request_log ⇒ Object
- #reset ⇒ Object
- #reset_cache ⇒ Object
- #reset_stubs ⇒ Object
- #restore_cache ⇒ Object
- #stubs ⇒ Object
Instance Method Details
#handle_request(method, url, headers, body) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/billy/handlers/request_handler.rb', line 17 def handle_request(method, url, headers, body) request = request_log.record(method, url, headers, body) # Process the handlers by order of importance [:stubs, :cache, :proxy].each do |key| if (response = handlers[key].handle_request(method, url, headers, body)) @request_log.complete(request, key) return response end end body_msg = Billy.config.cache_request_body_methods.include?(method) ? " with body '#{body}'" : '' request_log.complete(request, :error) { error: "Connection to #{url}#{body_msg} not cached and new http connections are disabled" } rescue => error { error: error. } end |
#handlers ⇒ Object
11 12 13 14 15 |
# File 'lib/billy/handlers/request_handler.rb', line 11 def handlers @handlers ||= { stubs: StubHandler.new, cache: CacheHandler.new, proxy: ProxyHandler.new } end |
#handles_request?(method, url, headers, body) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/billy/handlers/request_handler.rb', line 35 def handles_request?(method, url, headers, body) [:stubs, :cache, :proxy].any? do |key| handlers[key].handles_request?(method, url, headers, body) end end |
#request_log ⇒ Object
41 42 43 |
# File 'lib/billy/handlers/request_handler.rb', line 41 def request_log @request_log ||= RequestLog.new end |
#reset ⇒ Object
49 50 51 52 |
# File 'lib/billy/handlers/request_handler.rb', line 49 def reset handlers.each_value(&:reset) request_log.reset end |
#reset_cache ⇒ Object
58 59 60 |
# File 'lib/billy/handlers/request_handler.rb', line 58 def reset_cache handlers[:cache].reset end |
#reset_stubs ⇒ Object
54 55 56 |
# File 'lib/billy/handlers/request_handler.rb', line 54 def reset_stubs stub_handler.reset end |
#restore_cache ⇒ Object
62 63 64 65 |
# File 'lib/billy/handlers/request_handler.rb', line 62 def restore_cache warn '[DEPRECATION] `restore_cache` is deprecated as cache files are dynamically checked. Use `reset_cache` if you just want to clear the cache.' reset_cache end |
#stubs ⇒ Object
45 46 47 |
# File 'lib/billy/handlers/request_handler.rb', line 45 def stubs stub_handler.stubs end |