Class: Mongo::Cursor::Builder::KillCursorsCommand Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mongo/cursor/builder/kill_cursors_command.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.

Generates a specification for a kill cursors command.

Since:

  • 2.2.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cursor) ⇒ KillCursorsCommand

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.

Create the new builder.

Examples:

Create the builder.

KillCursorsCommand.new(cursor)

Parameters:

  • cursor (Cursor)

    The cursor.

Since:

  • 2.2.0



38
39
40
# File 'lib/mongo/cursor/builder/kill_cursors_command.rb', line 38

def initialize(cursor)
  @cursor = cursor
end

Instance Attribute Details

#cursorCursor (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.

Returns cursor The cursor.

Returns:

  • (Cursor)

    cursor The cursor.

Since:

  • 2.2.0



26
27
28
# File 'lib/mongo/cursor/builder/kill_cursors_command.rb', line 26

def cursor
  @cursor
end

Class Method Details

.get_cursors_list(spec) ⇒ Array<Integer>

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.

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

Examples:

Get the list of cursor ids.

KillCursorsCommand.cursors(spec)

Returns:

  • (Array<Integer>)

    The cursor ids.

Since:

  • 2.3.0



94
95
96
97
98
99
100
101
102
103
# File 'lib/mongo/cursor/builder/kill_cursors_command.rb', line 94

def get_cursors_list(spec)
  spec[:selector][:cursors].map do |value|
    if value.respond_to?(:value)
      # bson-ruby >= 4.6.0
      value = value.value
    else
      value = value.instance_variable_get('@integer')
    end
  end
end

.update_cursors(spec, ids) ⇒ Hash, Array<Integer>

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.

Update a specification’s list of cursor ids.

Examples:

Update a specification’s list of cursor ids.

KillCursorsCommand.update_cursors(spec, ids)

Returns:

  • (Hash)

    The specification.

  • (Array<Integer>)

    The ids to update with.

Since:

  • 2.3.0



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mongo/cursor/builder/kill_cursors_command.rb', line 74

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[:selector].merge!(cursors: ids)
end

Instance Method Details

#specificationHash

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.

Get the specification.

Examples:

Get the specification.

kill_cursors_command.specification

Returns:

  • (Hash)

    The spec.

Since:

  • 2.2.0



50
51
52
# File 'lib/mongo/cursor/builder/kill_cursors_command.rb', line 50

def specification
  { selector: kill_cursors_command, db_name: database.name }
end