Class: Stripe::StripeClient::ThreadContext
- Inherits:
-
Object
- Object
- Stripe::StripeClient::ThreadContext
- Defined in:
- lib/stripe/stripe_client.rb
Overview
A record representing any data that ‘StripeClient` 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
-
#active_client ⇒ Object
A ‘StripeClient` that’s been flagged as currently active within a thread by ‘StripeClient#request`.
-
#default_client ⇒ Object
A default ‘StripeClient` object for the thread.
-
#last_responses ⇒ Object
A temporary map of object IDs to responses from last executed API calls.
Instance Method Summary collapse
-
#default_connection_managers ⇒ Object
A map of connection managers for the thread.
- #reset_connection_managers ⇒ Object
Instance Attribute Details
#active_client ⇒ Object
A ‘StripeClient` that’s been flagged as currently active within a thread by ‘StripeClient#request`. A client stays active until the completion of the request block.
353 354 355 |
# File 'lib/stripe/stripe_client.rb', line 353 def active_client @active_client end |
#default_client ⇒ Object
A default ‘StripeClient` object for the thread. Used in all cases where the user hasn’t specified their own.
357 358 359 |
# File 'lib/stripe/stripe_client.rb', line 357 def default_client @default_client end |
#last_responses ⇒ Object
A temporary map of object IDs to responses from last executed API calls. Used to return a responses from calls to ‘StripeClient#request`.
Stored in the thread data to make the use of a single ‘StripeClient` object safe across multiple threads. Stored as a map so that multiple `StripeClient` 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 ‘StripeClient#request`, and because that’s wrapped in an ‘ensure` block, they should never leave garbage in `Thread.current`.
370 371 372 |
# File 'lib/stripe/stripe_client.rb', line 370 def last_responses @last_responses end |
Instance Method Details
#default_connection_managers ⇒ Object
A map of connection managers for the thread. Normally shared between all ‘StripeClient` objects on a particular thread, and created so as to minimize the number of open connections that an application needs.
375 376 377 |
# File 'lib/stripe/stripe_client.rb', line 375 def default_connection_managers @default_connection_managers ||= {} end |
#reset_connection_managers ⇒ Object
379 380 381 |
# File 'lib/stripe/stripe_client.rb', line 379 def reset_connection_managers @default_connection_managers = {} end |