diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 2d31add..bcff827 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -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. diff --git a/test/cursor_test.rb b/test/cursor_test.rb index 8ed4989..9bf14fb 100644 --- a/test/cursor_test.rb +++ b/test/cursor_test.rb @@ -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