class Mongo::Cursor::Builder::OpKillCursors

Encapsulates behavior around generating an OP_KILL_CURSORS specification.

@since 2.2.0

Attributes

cursor[R]

@return [ Cursor ] cursor The cursor.

Public Class Methods

get_cursors_list(spec) click to toggle source

Get the list of cursor ids from a spec generated by this Builder.

@example Get the list of cursor ids.

OpKillCursors.cursors(spec)

@return [ Array<Integer> ] The cursor ids.

@since 2.3.0

# File lib/mongo/cursor/builder/op_kill_cursors.rb, line 89
def get_cursors_list(spec)
  spec[:cursor_ids].map do |value|
    if value.respond_to?(:value)
      # bson-ruby >= 4.6.0
      value.value
    else
      value.instance_variable_get('@integer')
    end
  end
end
new(cursor) click to toggle source

Create the new builder.

@example Create the builder.

OpKillCursors.new(cursor)

@param [ Cursor ] cursor The cursor.

@since 2.2.0

# File lib/mongo/cursor/builder/op_kill_cursors.rb, line 38
def initialize(cursor)
  @cursor = cursor
end
update_cursors(spec, ids) click to toggle source

Update a specification's list of cursor ids.

@example Update a specification's list of cursor ids.

OpKillCursors.update_cursors(spec, ids)

@return [ Hash ] The specification. @return [ Array<Integer> ] The ids to update with.

@since 2.3.0

# File lib/mongo/cursor/builder/op_kill_cursors.rb, line 69
def update_cursors(spec, ids)
  # Ruby 2.5+ can & BSON::Int64 instances.
  # Ruby 2.4 and earlier cannot.
  # Convert stored ids to Ruby integers for compatibility with
  # older Rubies.
  ids = get_cursors_list(spec) & ids
  ids = ids.map do |cursor_id|
    BSON::Int64.new(cursor_id)
  end
  spec.merge!(cursor_ids: ids)
end

Public Instance Methods

specification() click to toggle source

Get the specification.

@example Get the specification.

op_kill_cursors.specification

@return [ Hash ] The specification.

@since 2.2.0

# File lib/mongo/cursor/builder/op_kill_cursors.rb, line 50
def specification
  {
    coll_name: collection_name,
    db_name: database.name,
    cursor_ids: [ BSON::Int64.new(cursor.id) ],
  }
end