Class: Mongo::Operation::Context Private
- Inherits:
-
Object
- Object
- Mongo::Operation::Context
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/operation/context.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
Instance Attribute Summary collapse
- #client ⇒ Object readonly private
- #options ⇒ Object readonly private
- #session ⇒ Object readonly private
Instance Method Summary collapse
- #aborting_transaction? ⇒ Boolean private
- #any_retry_writes? ⇒ Boolean private
- #committing_transaction? ⇒ Boolean private
- #connection_global_id ⇒ Object private
- #decrypt? ⇒ Boolean private
- #encrypt? ⇒ Boolean private
- #encrypter ⇒ Object private
- #in_transaction? ⇒ Boolean private
-
#initialize(client: nil, session: nil, connection_global_id: nil, options: nil) ⇒ Context
constructor
private
A new instance of Context.
- #legacy_retry_writes? ⇒ Boolean private
- #modern_retry_writes? ⇒ Boolean private
-
#retry? ⇒ Boolean
private
Whether the operation is a retry (true) or an initial attempt (false).
- #server_api ⇒ Object private
- #starting_transaction? ⇒ Boolean private
-
#with(**opts) ⇒ Object
private
Returns a new context with the parameters changed as per the provided arguments.
Constructor Details
#initialize(client: nil, session: nil, connection_global_id: nil, options: nil) ⇒ Context
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Context.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 38 def initialize(client: nil, session: nil, connection_global_id: nil, options: nil) if if client raise ArgumentError, 'Client and options cannot both be specified' end if session raise ArgumentError, 'Session and options cannot both be specified' end end if connection_global_id && session&.pinned_connection_global_id raise ArgumentError, 'Trying to pin context to a connection when the session is already pinned to a connection.' end @client = client @session = session @connection_global_id = connection_global_id @options = end |
Instance Attribute Details
#client ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 59 def client @client end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 61 def @options end |
#session ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
60 61 62 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 60 def session @session end |
Instance Method Details
#aborting_transaction? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 79 def aborting_transaction? in_transaction? && session.aborting_transaction? end |
#any_retry_writes? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
91 92 93 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 91 def any_retry_writes? modern_retry_writes? || legacy_retry_writes? end |
#committing_transaction? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 75 def committing_transaction? in_transaction? && session.committing_transaction? end |
#connection_global_id ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 63 def connection_global_id @connection_global_id || session&.pinned_connection_global_id end |
#decrypt? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
125 126 127 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 125 def decrypt? !!client&.encrypter end |
#encrypt? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
121 122 123 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 121 def encrypt? client&.encrypter&.encrypt? || false end |
#encrypter ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
129 130 131 132 133 134 135 |
# File 'build/ruby-driver-v2.19/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 |
#in_transaction? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 67 def in_transaction? session&.in_transaction? || false end |
#legacy_retry_writes? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 87 def legacy_retry_writes? client && !client.[:retry_writes] && client.max_write_retries > 0 end |
#modern_retry_writes? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 83 def modern_retry_writes? client && client.[:retry_writes] end |
#retry? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether the operation is a retry (true) or an initial attempt (false).
104 105 106 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 104 def retry? !!@is_retry end |
#server_api ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 101 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 95 def server_api if client client.[:server_api] elsif [:server_api] end end |
#starting_transaction? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'build/ruby-driver-v2.19/lib/mongo/operation/context.rb', line 71 def starting_transaction? session&.starting_transaction? || false end |
#with(**opts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new context with the parameters changed as per the provided arguments.
113 114 115 116 117 118 119 |
# File 'build/ruby-driver-v2.19/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 |