Class: Stripe::StripeClient::ThreadContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#active_clientObject

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.



342
343
344
# File 'lib/stripe/stripe_client.rb', line 342

def active_client
  @active_client
end

#default_clientObject

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



346
347
348
# File 'lib/stripe/stripe_client.rb', line 346

def default_client
  @default_client
end

#last_responsesObject

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`.



359
360
361
# File 'lib/stripe/stripe_client.rb', line 359

def last_responses
  @last_responses
end

Instance Method Details

#default_connection_managersObject

A map of connection mangers 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.



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

def default_connection_managers
  @default_connection_managers ||= {}
end

#reset_connection_managersObject



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

def reset_connection_managers
  @default_connection_managers = {}
end