lib/sniffer.rb in sniffer-0.1.0 vs lib/sniffer.rb in sniffer-0.2.0

- old
+ new

@@ -3,34 +3,32 @@ require "logger" require_relative "sniffer/version" require_relative "sniffer/config" require_relative "sniffer/data_item" +require_relative "sniffer/data" # Sniffer allows to log http requests module Sniffer - @data = Set.new - class << self - attr_reader :data - def config @config ||= Config.new yield @config if block_given? @config end def enable! - config.enabled = true + Thread.current[:sniffer] = true end def disable! - config.enabled = false + Thread.current[:sniffer] = false end def enabled? - config.enabled + Thread.current[:sniffer] = config.enabled if Thread.current[:sniffer].nil? + !!Thread.current[:sniffer] end def configure yield(config) if block_given? end @@ -39,15 +37,20 @@ data.clear end def reset! @config = Config.new + Thread.current[:sniffer] = config.enabled clear! end + def data + @data ||= Sniffer::Data.new + end + def store(data_item) - @data.add(data_item) if config.store + data.store(data_item) end def logger config.logger end @@ -58,5 +61,7 @@ require_relative "sniffer/adapters/httpclient_adapter" require_relative "sniffer/adapters/http_adapter" require_relative "sniffer/adapters/patron_adapter" require_relative "sniffer/adapters/curb_adapter" require_relative "sniffer/adapters/ethon_adapter" +require_relative "sniffer/adapters/eventmachine_adapter" +require_relative "sniffer/adapters/excon_adapter"