Module: Sniffer

Defined in:
lib/sniffer.rb,
lib/sniffer/data.rb,
lib/sniffer/config.rb,
lib/sniffer/version.rb,
lib/sniffer/data_item.rb,
lib/sniffer/request_policy.rb,
lib/sniffer/middleware/chain.rb,
lib/sniffer/middleware/entry.rb,
lib/sniffer/middleware/logger.rb,
lib/sniffer/adapters/curb_adapter.rb,
lib/sniffer/adapters/http_adapter.rb,
lib/sniffer/adapters/ethon_adapter.rb,
lib/sniffer/adapters/excon_adapter.rb,
lib/sniffer/adapters/patron_adapter.rb,
lib/sniffer/adapters/net_http_adapter.rb,
lib/sniffer/adapters/httpclient_adapter.rb,
lib/sniffer/adapters/eventmachine_adapter.rb

Overview

Sniffer allows to log http requests

Defined Under Namespace

Modules: Adapters, Middleware, RequestPolicy Classes: Config, Data, DataItem

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.clear!Object


36
37
38
# File 'lib/sniffer.rb', line 36

def clear!
  data.clear
end

.config {|@config| ... } ⇒ Object

Yields:


13
14
15
16
17
# File 'lib/sniffer.rb', line 13

def config
  @config ||= Config.new
  yield @config if block_given?
  @config
end

.configure {|config| ... } ⇒ Object

Yields:


32
33
34
# File 'lib/sniffer.rb', line 32

def configure
  yield(config) if block_given?
end

.dataObject


46
47
48
# File 'lib/sniffer.rb', line 46

def data
  @data ||= Sniffer::Data.new
end

.disable!Object


23
24
25
# File 'lib/sniffer.rb', line 23

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

.enable!Object


19
20
21
# File 'lib/sniffer.rb', line 19

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

.enabled?Boolean

Returns:

  • (Boolean)

27
28
29
30
# File 'lib/sniffer.rb', line 27

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

.notify_response(data_item) ⇒ Object


59
60
61
62
63
64
65
# File 'lib/sniffer.rb', line 59

def notify_response(data_item)
  return unless config.store
  return unless data_item.allowed_to_sniff?

  config.middleware.invoke_response(data_item) do
  end
end

.reset!Object


40
41
42
43
44
# File 'lib/sniffer.rb', line 40

def reset!
  @config = Config.new
  Thread.current[:sniffer] = config.enabled
  clear!
end

.store(data_item) ⇒ Object


50
51
52
53
54
55
56
57
# File 'lib/sniffer.rb', line 50

def store(data_item)
  return unless config.store
  return unless data_item.allowed_to_sniff?

  config.middleware.invoke_request(data_item) do
    data.store(data_item)
  end
end