RUBY-288 Cursor#remove_option

This commit is contained in:
Kyle Banker 2011-08-05 18:15:48 -04:00
parent 96b39313bf
commit 1142c33910
2 changed files with 19 additions and 4 deletions

View File

@ -350,12 +350,24 @@ module Mongo
#
# @param opt a valid query option
#
# @return [Integer] the current value of options for this cursor.
# @return [Integer] the current value of the options bitfield for this cursor.
#
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
def add_option(opt)
@options |= opt
return @options
@options
end
# Remove an option from the query options bitfield.
#
# @param opt a valid query option
#
# @return [Integer] the current value of the options bitfield for this cursor.
#
# @see http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
def remove_option(opt)
@options &= ~opt
@options
end
# Get the query options for this Cursor.

View File

@ -32,10 +32,13 @@ class CursorTest < Test::Unit::TestCase
@@coll.remove
end
def test_add_options
def test_add_and_remove_options
c = @@coll.find
assert_equal 0, c.options & OP_QUERY_EXHAUST
c.add_option(OP_QUERY_EXHAUST)
assert c.options & OP_QUERY_EXHAUST
assert_equal OP_QUERY_EXHAUST, c.options & OP_QUERY_EXHAUST
c.remove_option(OP_QUERY_EXHAUST)
assert_equal 0, c.options & OP_QUERY_EXHAUST
end
def test_inspect