Module: ActiveResourceHttpMock::ActiveResource::RequestLoggable

Defined in:
lib/active_resource_http_mock/active_resource/request_loggable.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_resource_http_mock/active_resource/request_loggable.rb', line 7

def self.included(base)
  base.class_eval do
    private

    # OPTIMIZE: It looks hard to swap Connection object with modified one as ActiveResource::* works together monolithically
    def request(method, path, *arguments)
      result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
        payload[:method]      = method
        payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
        payload[:request]     = arguments  # monkey patch for request logging
        payload[:result]      = http.send(method, path, *arguments)
      end
      handle_response(result)
    rescue Timeout::Error => e
      raise TimeoutError.new(e.message)
    rescue OpenSSL::SSL::SSLError => e
      raise SSLError.new(e.message)
    end
  end
end