Class: Rack::PactBroker::ResetThreadData

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/pact_broker/reset_thread_data.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ResetThreadData

Returns a new instance of ResetThreadData.



6
7
8
# File 'lib/rack/pact_broker/reset_thread_data.rb', line 6

def initialize app
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/pact_broker/reset_thread_data.rb', line 10

def call env
  data = OpenStruct.new
  Thread.current[:pact_broker_thread_data] ||= data
  response = @app.call(env)
  # only delete it if it's the same object that we set
  if data.equal?(Thread.current[:pact_broker_thread_data])
    Thread.current[:pact_broker_thread_data] = nil
  end
  response
end