Module: Samuel::DriverPatches::NetHTTP

Defined in:
lib/samuel/driver_patches/net_http.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/samuel/driver_patches/net_http.rb', line 4

def self.included(klass)
  methods_to_wrap = %w(request connect)
  methods_to_wrap.each do |method|
    klass.send(:alias_method, "#{method}_without_samuel", method)
    klass.send(:alias_method, method, "#{method}_with_samuel")
  end
end

Instance Method Details

#connect_with_samuelObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/samuel/driver_patches/net_http.rb', line 29

def connect_with_samuel
  connect_without_samuel
rescue Exception => response
  fake_request = Object.new
  def fake_request.path; ""; end
  def fake_request.method; "CONNECT"; end
  Samuel::Diary.record_request(self, fake_request)
  Samuel::Diary.record_response(self, fake_request, response)
  raise
end

#request_with_samuel(request, body = nil, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/samuel/driver_patches/net_http.rb', line 12

def request_with_samuel(request, body = nil, &block)
  response, exception_raised = nil, false
  request_time = Samuel::Diary.current_time

  begin
    response = request_without_samuel(request, body, &block)
  rescue Exception => response
    exception_raised = true
  end

  Samuel::Diary.record_request(self, request, request_time)
  Samuel::Diary.record_response(self, request, response)

  raise response if exception_raised
  response
end