class Mongo::Cursor::Builder::KillCursorsCommand
Generates a specification for a kill cursors command.
@since 2.2.0
Attributes
cursor[R]
@return [ Cursor
] cursor The cursor.
Public Class Methods
new(cursor)
click to toggle source
Create the new builder.
@example Create the builder.
KillCursorsCommand.new(cursor)
@param [ Cursor
] cursor The cursor.
@since 2.2.0
# File lib/mongo/cursor/builder/kill_cursors_command.rb, line 38 def initialize(cursor) @cursor = cursor end
Private 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.
KillCursorsCommand.cursors(spec)
@return [ Array<Integer> ] The cursor ids.
@since 2.3.0
# 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)
click to toggle source
Update a specification's list of cursor ids.
@example Update a specification's list of cursor ids.
KillCursorsCommand.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/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
Public Instance Methods
specification()
click to toggle source
Get the specification.
@example Get the specification.
kill_cursors_command.specification
@return [ Hash ] The spec.
@since 2.2.0
# File lib/mongo/cursor/builder/kill_cursors_command.rb, line 50 def specification { selector: kill_cursors_command, db_name: database.name } end
Private Instance Methods
kill_cursors_command()
click to toggle source
# File lib/mongo/cursor/builder/kill_cursors_command.rb, line 56 def kill_cursors_command { killCursors: collection_name, cursors: [ BSON::Int64.new(cursor.id) ], } end