use nil for BSON undefined instead of useless Undefined class. deprecate Undefined class
This commit is contained in:
parent
66e8d1a13b
commit
bb13fbe687
|
@ -42,7 +42,6 @@
|
|||
#define INITIAL_BUFFER_SIZE 256
|
||||
|
||||
static VALUE Binary;
|
||||
static VALUE Undefined;
|
||||
static VALUE Time;
|
||||
static VALUE ObjectID;
|
||||
static VALUE DBRef;
|
||||
|
@ -366,7 +365,7 @@ static int write_element_allow_id(VALUE key, VALUE value, VALUE extra, int allow
|
|||
break;
|
||||
}
|
||||
if (strcmp(cls, "XGen::Mongo::Driver::Undefined") == 0) {
|
||||
write_name_and_type(buffer, key, 0x06);
|
||||
write_name_and_type(buffer, key, 0x0A); // just use nil type
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -563,7 +562,7 @@ static VALUE get_value(const char* buffer, int* position, int type) {
|
|||
}
|
||||
case 6:
|
||||
{
|
||||
value = rb_class_new_instance(0, NULL, Undefined);
|
||||
value = Qnil;
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
|
@ -746,8 +745,6 @@ void Init_cbson() {
|
|||
rb_intern("Driver"));
|
||||
rb_require("mongo/types/binary");
|
||||
Binary = rb_const_get(driver, rb_intern("Binary"));
|
||||
rb_require("mongo/types/undefined");
|
||||
Undefined = rb_const_get(driver, rb_intern("Undefined"));
|
||||
rb_require("mongo/types/objectid");
|
||||
ObjectID = rb_const_get(driver, rb_intern("ObjectID"));
|
||||
rb_require("mongo/types/dbref");
|
||||
|
|
|
@ -18,14 +18,15 @@ module XGen
|
|||
module Mongo
|
||||
module Driver
|
||||
|
||||
# A special "undefined" type to match Mongo's storage of UNKNOWN values.
|
||||
# "UNKNOWN" comes from JavaScript.
|
||||
#
|
||||
# NOTE: this class does not attempt to provide ANY of the semantics an
|
||||
# "unknown" object might need. It isn't nil, it isn't special in any
|
||||
# way, and there isn't any singleton value.
|
||||
class Undefined < Object; end
|
||||
# DEPRECATED - the ruby driver converts the BSON undefined type to nil,
|
||||
# and saves this type as nil
|
||||
class Undefined < Object
|
||||
|
||||
def initialize
|
||||
super
|
||||
warn "the Undefined type is deprecated and will be removed - BSON undefineds get implicitely converted to nil now"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -135,7 +135,7 @@ class BSON
|
|||
when BINARY
|
||||
serialize_binary_element(@buf, k, v)
|
||||
when UNDEFINED
|
||||
serialize_undefined_element(@buf, k)
|
||||
serialize_null_element(@buf, k)
|
||||
when CODE_W_SCOPE
|
||||
serialize_code_w_scope(@buf, k, v)
|
||||
else
|
||||
|
@ -207,7 +207,7 @@ class BSON
|
|||
doc[key] = nil
|
||||
when UNDEFINED
|
||||
key = deserialize_cstr(@buf)
|
||||
doc[key] = Undefined.new
|
||||
doc[key] = nil
|
||||
when REF
|
||||
key = deserialize_cstr(@buf)
|
||||
doc[key] = deserialize_dbref_data(@buf)
|
||||
|
@ -385,11 +385,6 @@ class BSON
|
|||
end
|
||||
end
|
||||
|
||||
def serialize_undefined_element(buf, key)
|
||||
buf.put(UNDEFINED)
|
||||
self.class.serialize_cstr(buf, key)
|
||||
end
|
||||
|
||||
def serialize_boolean_element(buf, key, val)
|
||||
buf.put(BOOLEAN)
|
||||
self.class.serialize_cstr(buf, key)
|
||||
|
@ -543,7 +538,7 @@ class BSON
|
|||
when Symbol
|
||||
SYMBOL
|
||||
when Undefined
|
||||
UNDEFINED
|
||||
NULL
|
||||
else
|
||||
raise "Unknown type of object: #{o.class.name}"
|
||||
end
|
||||
|
|
|
@ -63,8 +63,6 @@ class XMLToRuby
|
|||
regex_to_ruby(e.elements)
|
||||
when 'null'
|
||||
nil
|
||||
when 'undefined'
|
||||
Undefined.new
|
||||
when 'doc'
|
||||
doc_to_ruby(e)
|
||||
else
|
||||
|
|
|
@ -183,7 +183,7 @@ class BSONTest < Test::Unit::TestCase
|
|||
doc = {'undef' => Undefined.new}
|
||||
@b.serialize(doc)
|
||||
doc2 = @b.deserialize
|
||||
assert_kind_of Undefined, doc2['undef']
|
||||
assert_equal nil, doc2['undef']
|
||||
end
|
||||
|
||||
def test_put_id_first
|
||||
|
|
|
@ -64,7 +64,11 @@ EOS
|
|||
# generated)
|
||||
def one_round_trip(dir, name)
|
||||
obj = File.open(File.join(dir, "#{name}.xson")) { |f|
|
||||
begin
|
||||
XMLToRuby.new.xml_to_ruby(f)
|
||||
rescue => ex # unsupported type
|
||||
return
|
||||
end
|
||||
}
|
||||
|
||||
File.open(File.join(dir, "#{name}.bson"), 'rb') { |f|
|
||||
|
|
Loading…
Reference in New Issue