You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: executable.rb
    path of file: ./repos/mongo-ruby-driver/lib/mongo/operation/shared
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
# rubocop:todo all

# Copyright (C) 2015-2020 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'mongo/error'

module Mongo
  module Operation

    # Shared executable behavior of operations.
    #
    # @since 2.5.2
    # @api private
    module Executable

      include ResponseHandling

      def do_execute(connection, context, options = {})
        session&.materialize_if_needed
        unpin_maybe(session, connection) do
          add_error_labels(connection, context) do
            check_for_network_error do
              add_server_diagnostics(connection) do
                get_result(connection, context, options).tap do |result|
                  if session
                    if session.in_transaction? &&
                      connection.description.load_balancer?
                    then
                      if session.pinned_connection_global_id
                        unless
    
      def do_execute(connection, context, options = {})
        session&.materialize_if_needed
        unpin_maybe(session, connection) do
          add_error_labels(connection, context) do
            check_for_network_error do
              add_server_diagnostics(connection) do
                get_result(connection, context, options).tap do |result|
                  if session
                    if session.in_transaction? &&
                      connection.description.load_balancer?
                    then
                      if session.pinned_connection_global_id
                        unless session.pinned_connection_global_id == connection.global_id
                          raise(
                            Error::InternalDriverError,
                            "Expected operation to use connection #{session.pinned_connection_global_id} but it used #{connection.global_id}"
                          )
                        end
                      else
                        session.pin_to_connection(connection.global_id)
                        connection.pin
                      end
                    end

                    if session.snapshot? && !session.snapshot_timestamp
                      session.snapshot_timestamp = result.snapshot_timestamp
                    end
                  end

                  if result.has_cursor_id? &&
                    connection.description.load_balancer?
                  then
                    if result.cursor_id == 0
                      connection.unpin
                    else
                      connection.pin
                    end