Class: Mongo::Operation::Context Private
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/mongo/operation/context.rb |
Overview
Context
for operations.
Holds various objects needed to make decisions about operation execution in a single container, and provides facade methods for the contained objects.
The context contains parameters for operations, and as such while an operation is being prepared nothing in the context should change. When the result of the operation is being processed, the data returned by the context may change (for example, because a transaction is aborted), but at that point the operation should no longer read anything from the context. Because context data may change during operation execution, context objects should not be reused for multiple operations.
Class Method Summary
- .new(client: nil, session: nil, connection_global_id: nil, options: nil) ⇒ Context constructor Internal use only
Instance Attribute Summary
- #aborting_transaction? ⇒ Boolean readonly Internal use only
- #any_retry_writes? ⇒ Boolean readonly Internal use only
- #client readonly Internal use only
- #committing_transaction? ⇒ Boolean readonly Internal use only
- #decrypt? ⇒ Boolean readonly Internal use only
- #encrypt? ⇒ Boolean readonly Internal use only
- #in_transaction? ⇒ Boolean readonly Internal use only
- #legacy_retry_writes? ⇒ Boolean readonly Internal use only
- #modern_retry_writes? ⇒ Boolean readonly Internal use only
- #options readonly Internal use only
-
#retry? ⇒ Boolean
readonly
Internal use only
Whether the operation is a retry (true) or an initial attempt (false).
- #session readonly Internal use only
- #starting_transaction? ⇒ Boolean readonly Internal use only
Instance Method Summary
- #connection_global_id Internal use only
- #encrypter Internal use only
- #server_api Internal use only
-
#with(**opts)
Internal use only
Returns a new context with the parameters changed as per the provided arguments.
Instance Attribute Details
#aborting_transaction? ⇒ Boolean
(readonly)
# File 'lib/mongo/operation/context.rb', line 79
def aborting_transaction? in_transaction? && session.aborting_transaction? end
#any_retry_writes? ⇒ Boolean
(readonly)
# File 'lib/mongo/operation/context.rb', line 91
def any_retry_writes? modern_retry_writes? || legacy_retry_writes? end
#client (readonly)
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 59
attr_reader :client
#committing_transaction? ⇒ Boolean
(readonly)
# File 'lib/mongo/operation/context.rb', line 75
def committing_transaction? in_transaction? && session.committing_transaction? end
#decrypt? ⇒ Boolean
(readonly)
#encrypt? ⇒ Boolean
(readonly)
#in_transaction? ⇒ Boolean
(readonly)
# File 'lib/mongo/operation/context.rb', line 67
def in_transaction? session&.in_transaction? || false end
#legacy_retry_writes? ⇒ Boolean
(readonly)
#modern_retry_writes? ⇒ Boolean
(readonly)
#options (readonly)
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 61
attr_reader :
#retry? ⇒ Boolean
(readonly)
Whether the operation is a retry (true) or an initial attempt (false).
# File 'lib/mongo/operation/context.rb', line 104
def retry? !!@is_retry end
#session (readonly)
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 60
attr_reader :session
#starting_transaction? ⇒ Boolean
(readonly)
# File 'lib/mongo/operation/context.rb', line 71
def starting_transaction? session&.starting_transaction? || false end
Instance Method Details
#connection_global_id
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 63
def connection_global_id @connection_global_id || session&.pinned_connection_global_id end
#encrypter
[ GitHub ]# File 'lib/mongo/operation/context.rb', line 129
def encrypter if client&.encrypter client.encrypter else raise Error::InternalDriverError, 'Encrypter should only be accessed when encryption is to be performed' end end
#server_api
[ GitHub ]#with(**opts)
Returns a new context with the parameters changed as per the provided arguments.
# File 'lib/mongo/operation/context.rb', line 113
def with(**opts) dup.tap do |copy| opts.each do |k, v| copy.instance_variable_set("@#{k}", v) end end end