Class: IdempotencyCheck::HttpTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/idempotency_check/http_tracker.rb

Overview

Counts how many outbound HTTP requests happen inside a block, by wrapping Net::HTTP#request. We can't verify idempotency of external side effects, so this is only used to flag results as suspicious.

Class Method Summary collapse

Class Method Details

.trackObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/idempotency_check/http_tracker.rb', line 10

def self.track
  count = 0
  original = Net::HTTP.instance_method(:request)

  Net::HTTP.send(:define_method, :request) do |*args, &blk|
    count += 1
    original.bind(self).call(*args, &blk)
  end

  yield

  count
ensure
  Net::HTTP.send(:define_method, :request, original) if original
end