Sha256: 3dfe82df9d3935e6c5d4c6d987ec1c7dbe68b0f6bea88e3d916056f06a38603b

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

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
  class << self
    def config
      @config ||= Config.new
      yield @config if block_given?
      @config
    end

    def enable!
      Thread.current[:sniffer] = true
    end

    def disable!
      Thread.current[:sniffer] = false
    end

    def enabled?
      Thread.current[:sniffer] = config.enabled if Thread.current[:sniffer].nil?
      !!Thread.current[:sniffer]
    end

    def configure
      yield(config) if block_given?
    end

    def clear!
      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.store(data_item) if config.store
    end

    def logger
      config.logger
    end
  end
end

require_relative "sniffer/adapters/net_http_adapter"
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"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sniffer-0.3.2 lib/sniffer.rb
sniffer-0.3.1 lib/sniffer.rb
sniffer-0.3.0 lib/sniffer.rb