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
|
= 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.
|
* Change find(selector={}, fields=nil, options={}) to find(selector={},
|
||||||
That's what I should be writing to.
|
options={})
|
||||||
|
|
||||||
|
* ObjectID equality.
|
||||||
|
|
||||||
* Capped collection support.
|
* Capped collection support.
|
||||||
|
|
||||||
* More code comments. More text in this file.
|
* More code comments. More text in this file.
|
||||||
|
|
||||||
* Rake task for rdoc generation.
|
* Support more types: REF, SYMBOL, CODE_W_SCOPE, etc.
|
||||||
|
|
||||||
* Remove default _id generation.
|
|
||||||
|
|
||||||
* Introduce optional per-database and per-collection PKInjector.
|
* Introduce optional per-database and per-collection PKInjector.
|
||||||
|
|
||||||
|
@ -73,7 +73,8 @@ type
|
||||||
|
|
||||||
* Implement Admin.
|
* 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
|
= Credits
|
||||||
|
|
|
@ -22,6 +22,8 @@ module XGen
|
||||||
|
|
||||||
include Comparable
|
include Comparable
|
||||||
|
|
||||||
|
include Comparable
|
||||||
|
|
||||||
@@uuid_generator = UUID.new
|
@@uuid_generator = UUID.new
|
||||||
|
|
||||||
# String UUID
|
# String UUID
|
||||||
|
@ -37,7 +39,9 @@ module XGen
|
||||||
def to_s
|
def to_s
|
||||||
@uuid
|
@uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This will make more sense when we implement the Babble algorithm for
|
||||||
|
# generating object ids.
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
to_s <=> other.to_s
|
to_s <=> other.to_s
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,8 @@ class BSON
|
||||||
serialize_oid_element(@buf, k, v)
|
serialize_oid_element(@buf, k, v)
|
||||||
when ARRAY
|
when ARRAY
|
||||||
serialize_array_element(@buf, k, v)
|
serialize_array_element(@buf, k, v)
|
||||||
|
when REGEX
|
||||||
|
serialize_regex_element(@buf, k, v)
|
||||||
when BOOLEAN
|
when BOOLEAN
|
||||||
serialize_boolean_element(@buf, k, v)
|
serialize_boolean_element(@buf, k, v)
|
||||||
when DATE
|
when DATE
|
||||||
|
@ -97,6 +99,9 @@ class BSON
|
||||||
when ARRAY
|
when ARRAY
|
||||||
key = deserialize_element_name(@buf)
|
key = deserialize_element_name(@buf)
|
||||||
doc[key] = deserialize_array_data(@buf)
|
doc[key] = deserialize_array_data(@buf)
|
||||||
|
when REGEX
|
||||||
|
key = deserialize_element_name(@buf)
|
||||||
|
doc[key] = deserialize_regex_data(@buf)
|
||||||
when OBJECT
|
when OBJECT
|
||||||
key = deserialize_element_name(@buf)
|
key = deserialize_element_name(@buf)
|
||||||
doc[key] = deserialize_object_data(@buf)
|
doc[key] = deserialize_object_data(@buf)
|
||||||
|
@ -162,6 +167,16 @@ class BSON
|
||||||
a
|
a
|
||||||
end
|
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)
|
def deserialize_string_data(buf)
|
||||||
len = buf.get_int
|
len = buf.get_int
|
||||||
bytes = buf.get(len)
|
bytes = buf.get(len)
|
||||||
|
@ -220,6 +235,21 @@ class BSON
|
||||||
serialize_object_element(buf, key, h, ARRAY)
|
serialize_object_element(buf, key, h, ARRAY)
|
||||||
end
|
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)
|
def serialize_oid_element(buf, key, val)
|
||||||
buf.put(OID)
|
buf.put(OID)
|
||||||
self.class.serialize_cstr(buf, key)
|
self.class.serialize_cstr(buf, key)
|
||||||
|
@ -274,6 +304,8 @@ class BSON
|
||||||
key == "$where" ? CODE : STRING
|
key == "$where" ? CODE : STRING
|
||||||
when Array
|
when Array
|
||||||
ARRAY
|
ARRAY
|
||||||
|
when Regexp
|
||||||
|
REGEX
|
||||||
when XGen::Mongo::Driver::ObjectID
|
when XGen::Mongo::Driver::ObjectID
|
||||||
OID
|
OID
|
||||||
when true, false
|
when true, false
|
||||||
|
|
|
@ -7,8 +7,8 @@ require 'test/unit'
|
||||||
class DBAPITest < Test::Unit::TestCase
|
class DBAPITest < Test::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
host = ENV['HOST'] || ENV['host'] || 'localhost'
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||||
port = ENV['PORT'] || ENV['port'] || 27017
|
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
||||||
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
||||||
@coll = @db.collection('test')
|
@coll = @db.collection('test')
|
||||||
@coll.clear
|
@coll.clear
|
||||||
|
@ -186,6 +186,14 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
assert_equal [1, 2, 3], rows[0]['b']
|
assert_equal [1, 2, 3], rows[0]['b']
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def new_oid
|
def new_oid
|
||||||
|
|
|
@ -8,6 +8,8 @@ class DBConnectionTest < Test::Unit::TestCase
|
||||||
def test_no_exceptions
|
def test_no_exceptions
|
||||||
host = ENV['HOST'] || ENV['host'] || 'localhost'
|
host = ENV['HOST'] || ENV['host'] || 'localhost'
|
||||||
port = ENV['PORT'] || ENV['port'] || 27017
|
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')
|
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
||||||
coll = db.collection('test')
|
coll = db.collection('test')
|
||||||
coll.clear
|
coll.clear
|
||||||
|
|
Loading…
Reference in New Issue