Merge branch 'master' of git://github.com/jimm/mongo-ruby-driver
This commit is contained in:
commit
af8364db7a
15
README
15
README
|
@ -52,18 +52,18 @@ type
|
|||
|
||||
= To Do
|
||||
|
||||
* Support more types: REGEX, etc.
|
||||
* Implement Babble's algorithm for ObjectID. Implement Comparable.
|
||||
|
||||
* Study src/main/ed/db/{dbcollection,dbcursor,db}.js in the Babble code.
|
||||
That's what I should be writing to.
|
||||
* Change find(selector={}, fields=nil, options={}) to find(selector={},
|
||||
options={})
|
||||
|
||||
* ObjectID equality.
|
||||
|
||||
* Capped collection support.
|
||||
|
||||
* More code comments. More text in this file.
|
||||
|
||||
* Rake task for rdoc generation.
|
||||
|
||||
* Remove default _id generation.
|
||||
* Support more types: REF, SYMBOL, CODE_W_SCOPE, etc.
|
||||
|
||||
* Introduce optional per-database and per-collection PKInjector.
|
||||
|
||||
|
@ -73,7 +73,8 @@ type
|
|||
|
||||
* Implement Admin.
|
||||
|
||||
* See FIXME in db test.
|
||||
* Study src/main/ed/db/{dbcollection,dbcursor,db}.js and ByteEncoder.java in
|
||||
the Babble code. That's what I should be writing to.
|
||||
|
||||
|
||||
= Credits
|
||||
|
|
|
@ -22,6 +22,8 @@ module XGen
|
|||
|
||||
include Comparable
|
||||
|
||||
include Comparable
|
||||
|
||||
@@uuid_generator = UUID.new
|
||||
|
||||
# String UUID
|
||||
|
@ -37,7 +39,9 @@ module XGen
|
|||
def to_s
|
||||
@uuid
|
||||
end
|
||||
|
||||
|
||||
# This will make more sense when we implement the Babble algorithm for
|
||||
# generating object ids.
|
||||
def <=>(other)
|
||||
to_s <=> other.to_s
|
||||
end
|
||||
|
|
|
@ -59,6 +59,8 @@ class BSON
|
|||
serialize_oid_element(@buf, k, v)
|
||||
when ARRAY
|
||||
serialize_array_element(@buf, k, v)
|
||||
when REGEX
|
||||
serialize_regex_element(@buf, k, v)
|
||||
when BOOLEAN
|
||||
serialize_boolean_element(@buf, k, v)
|
||||
when DATE
|
||||
|
@ -97,6 +99,9 @@ class BSON
|
|||
when ARRAY
|
||||
key = deserialize_element_name(@buf)
|
||||
doc[key] = deserialize_array_data(@buf)
|
||||
when REGEX
|
||||
key = deserialize_element_name(@buf)
|
||||
doc[key] = deserialize_regex_data(@buf)
|
||||
when OBJECT
|
||||
key = deserialize_element_name(@buf)
|
||||
doc[key] = deserialize_object_data(@buf)
|
||||
|
@ -162,6 +167,16 @@ class BSON
|
|||
a
|
||||
end
|
||||
|
||||
def deserialize_regex_data(buf)
|
||||
str = deserialize_element_name(buf)
|
||||
options_str = deserialize_element_name(buf)
|
||||
options = 0
|
||||
options |= Regexp::IGNORECASE if options_str.include?('i')
|
||||
options |= Regexp::MULTILINE if options_str.include?('m')
|
||||
options |= Regexp::EXTENDED if options_str.include?('x')
|
||||
Regexp.new(str, options)
|
||||
end
|
||||
|
||||
def deserialize_string_data(buf)
|
||||
len = buf.get_int
|
||||
bytes = buf.get(len)
|
||||
|
@ -220,6 +235,21 @@ class BSON
|
|||
serialize_object_element(buf, key, h, ARRAY)
|
||||
end
|
||||
|
||||
def serialize_regex_element(buf, key, val)
|
||||
buf.put(REGEX)
|
||||
self.class.serialize_cstr(buf, key)
|
||||
|
||||
str = val.to_s.sub(/.*?:/, '')[0..-2] # Turn "(?xxx:yyy)" into "yyy"
|
||||
self.class.serialize_cstr(buf, str)
|
||||
|
||||
options = val.options
|
||||
options_str = ''
|
||||
options_str << 'i' if ((options & Regexp::IGNORECASE) != 0)
|
||||
options_str << 'm' if ((options & Regexp::MULTILINE) != 0)
|
||||
options_str << 'x' if ((options & Regexp::EXTENDED) != 0)
|
||||
self.class.serialize_cstr(buf, options_str)
|
||||
end
|
||||
|
||||
def serialize_oid_element(buf, key, val)
|
||||
buf.put(OID)
|
||||
self.class.serialize_cstr(buf, key)
|
||||
|
@ -274,6 +304,8 @@ class BSON
|
|||
key == "$where" ? CODE : STRING
|
||||
when Array
|
||||
ARRAY
|
||||
when Regexp
|
||||
REGEX
|
||||
when XGen::Mongo::Driver::ObjectID
|
||||
OID
|
||||
when true, false
|
||||
|
|
|
@ -7,8 +7,8 @@ require 'test/unit'
|
|||
class DBAPITest < Test::Unit::TestCase
|
||||
|
||||
def setup
|
||||
host = ENV['HOST'] || ENV['host'] || 'localhost'
|
||||
port = ENV['PORT'] || ENV['port'] || 27017
|
||||
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
||||
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
||||
@coll = @db.collection('test')
|
||||
@coll.clear
|
||||
|
@ -186,6 +186,14 @@ class DBAPITest < Test::Unit::TestCase
|
|||
assert_equal [1, 2, 3], rows[0]['b']
|
||||
end
|
||||
|
||||
def test_regex
|
||||
regex = /foobar/i
|
||||
@coll << {'b' => regex}
|
||||
rows = @coll.find({}, {'b' => 1}).collect
|
||||
assert_equal 1, rows.length
|
||||
assert_equal regex, rows[0]['b']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def new_oid
|
||||
|
|
|
@ -8,6 +8,8 @@ class DBConnectionTest < Test::Unit::TestCase
|
|||
def test_no_exceptions
|
||||
host = ENV['HOST'] || ENV['host'] || 'localhost'
|
||||
port = ENV['PORT'] || ENV['port'] || 27017
|
||||
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
||||
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
||||
coll = db.collection('test')
|
||||
coll.clear
|
||||
|
|
Loading…
Reference in New Issue