Skip to content

Commit

Permalink
Use global callbacks instead global_hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshasselberg committed Aug 23, 2012
1 parent 4498816 commit 8ba313e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ def self.disabled?
end end


def self.add_after_request_callback def self.add_after_request_callback
unless Typhoeus::Hydra. unless Typhoeus.on_complete.include?(AFTER_REQUEST_CALLBACK)
global_hooks[:after_request_before_on_complete]. Typhoeus.on_complete << AFTER_REQUEST_CALLBACK
include?(AFTER_REQUEST_CALLBACK)
Typhoeus::Hydra.
global_hooks[:after_request_before_on_complete] << AFTER_REQUEST_CALLBACK
end end
end end


def self.remove_after_request_callback def self.remove_after_request_callback
Typhoeus::Hydra.global_hooks[:after_request_before_on_complete]. Typhoeus.on_complete.delete_if {|v| v == AFTER_REQUEST_CALLBACK }
delete_if {|v| v == AFTER_REQUEST_CALLBACK }
end end


def self.build_request_signature(req) def self.build_request_signature(req)
Expand Down Expand Up @@ -118,12 +114,13 @@ def self.request_hash(request_signature)
hash hash
end end


AFTER_REQUEST_CALLBACK = Proc.new do |request| AFTER_REQUEST_CALLBACK = Proc.new do |response|
request = response.request
request_signature = request.instance_variable_get(:@__webmock_request_signature) request_signature = request.instance_variable_get(:@__webmock_request_signature)
webmock_response = webmock_response =
::WebMock::HttpLibAdapters::TyphoeusAdapter. ::WebMock::HttpLibAdapters::TyphoeusAdapter.
build_webmock_response(request.response) build_webmock_response(response)
if request.response.mock? if response.mock
WebMock::CallbackRegistry.invoke_callbacks( WebMock::CallbackRegistry.invoke_callbacks(
{:lib => :typhoeus}, {:lib => :typhoeus},
request_signature, request_signature,
Expand Down

0 comments on commit 8ba313e

Please sign in to comment.