Class: Billy::RequestHandler

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Handler
Defined in:
lib/billy/handlers/request_handler.rb

Instance Method Summary collapse

Instance Method Details

#handle_request(method, url, headers, body) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/billy/handlers/request_handler.rb', line 16

def handle_request(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))
      return response
    end
  end

  body_msg = Billy.config.cache_request_body_methods.include?(method) ? " with body '#{body}'" : ''
  { error: "Connection to #{url}#{body_msg} not cached and new http connections are disabled" }
end

#handlersObject



10
11
12
13
14
# File 'lib/billy/handlers/request_handler.rb', line 10

def handlers
  @handlers ||= { stubs: StubHandler.new,
                  cache: CacheHandler.new,
                  proxy: ProxyHandler.new }
end

#handles_request?(method, url, headers, body) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/billy/handlers/request_handler.rb', line 28

def handles_request?(method, url, headers, body)
  [:stubs, :cache, :proxy].each do |key|
    return true if handlers[key].handles_request?(method, url, headers, body)
  end

  false
end

#resetObject



36
37
38
# File 'lib/billy/handlers/request_handler.rb', line 36

def reset
  handlers.each_value(&:reset)
end

#reset_cacheObject



44
45
46
# File 'lib/billy/handlers/request_handler.rb', line 44

def reset_cache
  handlers[:cache].reset
end

#reset_stubsObject



40
41
42
# File 'lib/billy/handlers/request_handler.rb', line 40

def reset_stubs
  handlers[:stubs].reset
end

#restore_cacheObject



48
49
50
51
# File 'lib/billy/handlers/request_handler.rb', line 48

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