lib/sniffer/adapters/curb_adapter.rb in sniffer-0.4.0 vs lib/sniffer/adapters/curb_adapter.rb in sniffer-0.5.0

- old
+ new

@@ -2,20 +2,10 @@ module Sniffer module Adapters # Curl adapter module CurlAdapter - def self.included(base) - base.class_eval do - alias_method :http_without_sniffer, :http - alias_method :http, :http_with_sniffer - - alias_method :http_post_without_sniffer, :http_post - alias_method :http_post, :http_post_with_sniffer - end - end - def http_with_sniffer(verb) sniffer_request(verb) http_without_sniffer(verb) @@ -38,10 +28,41 @@ sniffer_response(bm) @res end + # Only used when prepending, see all_prepend.rb + module Prepend + include CurlAdapter + + def http(verb) + sniffer_request(verb) + + super(verb) + + bm = Benchmark.realtime do + @res = super(verb) + end + + sniffer_response(bm) + + @res + end + + def http_post(*args) + sniffer_request(:POST, *args) + + bm = Benchmark.realtime do + @res = super(*args) + end + + sniffer_response(bm) + + @res + end + end + private def data_item @data_item ||= Sniffer::DataItem.new if Sniffer.enabled? end @@ -80,6 +101,19 @@ end end end end -Curl::Easy.include Sniffer::Adapters::CurlAdapter if defined?(::Curl::Easy) +if defined?(::Curl::Easy) + if defined?(Sniffer::Adapters::CurlAdapter::PREPEND) + Curl::Easy.prepend Sniffer::Adapters::CurlAdapter::Prepend + else + Curl::Easy.class_eval do + include Sniffer::Adapters::CurlAdapter + alias_method :http_without_sniffer, :http + alias_method :http, :http_with_sniffer + + alias_method :http_post_without_sniffer, :http_post + alias_method :http_post, :http_post_with_sniffer + end + end +end