Class: Stripe::APIRequestor::ThreadContext

Inherits:
Object
  • Object
show all
Defined in:
lib/stripe/api_requestor.rb

Overview

A record representing any data that ‘APIRequestor` puts into `Thread.current`. Making it a class likes this gives us a little extra type safety and lets us document what each field does.

For internal use only. Does not provide a stable API and may be broken with future non-major changes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active_requestorObject

A ‘APIRequestor` that’s been flagged as currently active within a thread by ‘APIRequestor#request`. A requestor stays active until the completion of the request block.



364
365
366
# File 'lib/stripe/api_requestor.rb', line 364

def active_requestor
  @active_requestor
end

#default_requestorObject

A default ‘APIRequestor` object for the thread. Used in all cases where the user hasn’t specified their own.



368
369
370
# File 'lib/stripe/api_requestor.rb', line 368

def default_requestor
  @default_requestor
end

#last_responsesObject

A temporary map of object IDs to responses from last executed API calls. Used to return a responses from calls to ‘APIRequestor#request`.

Stored in the thread data to make the use of a single ‘APIRequestor` object safe across multiple threads. Stored as a map so that multiple `APIRequestor` objects can run concurrently on the same thread.

Responses are only left in as long as they’re needed, which means they’re removed as soon as a call leaves ‘APIRequestor#request`, and because that’s wrapped in an ‘ensure` block, they should never leave garbage in `Thread.current`.



381
382
383
# File 'lib/stripe/api_requestor.rb', line 381

def last_responses
  @last_responses
end

Instance Method Details

#default_connection_managersObject

A map of connection mangers for the thread. Normally shared between all ‘APIRequestor` objects on a particular thread, and created so as to minimize the number of open connections that an application needs.



386
387
388
# File 'lib/stripe/api_requestor.rb', line 386

def default_connection_managers
  @default_connection_managers ||= {}
end

#reset_connection_managersObject



390
391
392
# File 'lib/stripe/api_requestor.rb', line 390

def reset_connection_managers
  @default_connection_managers = {}
end