bson_ext 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -58,23 +58,48 @@ namespace :test do
58
58
  t.verbose = true
59
59
  end
60
60
 
61
- Rake::TestTask.new(:pair_count) do |t|
62
- t.test_files = FileList['test/replica/count_test.rb']
61
+ Rake::TestTask.new(:replica_pair_count) do |t|
62
+ t.test_files = FileList['test/replica_pairs/count_test.rb']
63
63
  t.verbose = true
64
64
  end
65
65
 
66
- Rake::TestTask.new(:pair_insert) do |t|
67
- t.test_files = FileList['test/replica/insert_test.rb']
66
+ Rake::TestTask.new(:replica_pair_insert) do |t|
67
+ t.test_files = FileList['test/replica_pairs/insert_test.rb']
68
68
  t.verbose = true
69
69
  end
70
70
 
71
- Rake::TestTask.new(:pooled_pair_insert) do |t|
72
- t.test_files = FileList['test/replica/pooled_insert_test.rb']
71
+ Rake::TestTask.new(:pooled_replica_pair_insert) do |t|
72
+ t.test_files = FileList['test/replica_pairs/pooled_insert_test.rb']
73
73
  t.verbose = true
74
74
  end
75
75
 
76
- Rake::TestTask.new(:pair_query) do |t|
77
- t.test_files = FileList['test/replica/query_test.rb']
76
+ Rake::TestTask.new(:replica_pair_query) do |t|
77
+ t.test_files = FileList['test/replica_pairs/query_test.rb']
78
+ t.verbose = true
79
+ end
80
+
81
+ Rake::TestTask.new(:replica_set_count) do |t|
82
+ t.test_files = FileList['test/replica_sets/count_test.rb']
83
+ t.verbose = true
84
+ end
85
+
86
+ Rake::TestTask.new(:replica_set_insert) do |t|
87
+ t.test_files = FileList['test/replica_sets/insert_test.rb']
88
+ t.verbose = true
89
+ end
90
+
91
+ Rake::TestTask.new(:pooled_replica_set_insert) do |t|
92
+ t.test_files = FileList['test/replica_sets/pooled_insert_test.rb']
93
+ t.verbose = true
94
+ end
95
+
96
+ Rake::TestTask.new(:replica_set_query) do |t|
97
+ t.test_files = FileList['test/replica_sets/query_test.rb']
98
+ t.verbose = true
99
+ end
100
+
101
+ Rake::TestTask.new(:replica_set_ack) do |t|
102
+ t.test_files = FileList['test/replica_sets/replication_ack_test.rb']
78
103
  t.verbose = true
79
104
  end
80
105
 
@@ -1,4 +1,4 @@
1
- require 'lib/bson'
1
+ require './lib/bson'
2
2
  VERSION_HEADER = File.open(File.join(File.dirname(__FILE__), 'ext', 'cbson', 'version.h'), "r")
3
3
  VERSION = VERSION_HEADER.read.scan(/VERSION\s+"(\d+\.\d+(\.\d+\w*)?)\"/)[0][0]
4
4
  Gem::Specification.new do |s|
@@ -73,8 +73,8 @@
73
73
  #define MAX_HOSTNAME_LENGTH 256
74
74
 
75
75
  static VALUE Binary;
76
- static VALUE Time;
77
76
  static VALUE ObjectID;
77
+ static VALUE ObjectId;
78
78
  static VALUE DBRef;
79
79
  static VALUE Code;
80
80
  static VALUE MinKey;
@@ -379,7 +379,7 @@ static int write_element(VALUE key, VALUE value, VALUE extra, int allow_id) {
379
379
  SAFE_WRITE(buffer, RSTRING_PTR(string_data), length);
380
380
  break;
381
381
  }
382
- if (strcmp(cls, "BSON::ObjectID") == 0) {
382
+ if ((strcmp(cls, "BSON::ObjectId") == 0) || (strcmp(cls, "BSON::ObjectID") == 0)) {
383
383
  VALUE as_array = rb_funcall(value, rb_intern("to_a"), 0);
384
384
  int i;
385
385
  write_name_and_type(buffer, key, 0x07);
@@ -561,8 +561,12 @@ static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_
561
561
 
562
562
  write_function(key, value, pack_extra(buffer, check_keys));
563
563
  }
564
- } else {
564
+ } else if (strcmp(rb_obj_classname(hash), "Hash") == 0) {
565
565
  rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys));
566
+ } else {
567
+ buffer_free(buffer);
568
+ char* cls = rb_obj_classname(hash);
569
+ rb_raise(InvalidDocument, "BSON.serialize takes a Hash but got a %s", cls);
566
570
  }
567
571
 
568
572
  // write null byte and fill in length
@@ -691,7 +695,7 @@ static VALUE get_value(const char* buffer, int* position, int type) {
691
695
  {
692
696
  VALUE str = rb_str_new(buffer + *position, 12);
693
697
  VALUE oid = rb_funcall(str, rb_intern("unpack"), 1, rb_str_new2("C*"));
694
- value = rb_class_new_instance(1, &oid, ObjectID);
698
+ value = rb_class_new_instance(1, &oid, ObjectId);
695
699
  *position += 12;
696
700
  break;
697
701
  }
@@ -703,12 +707,9 @@ static VALUE get_value(const char* buffer, int* position, int type) {
703
707
  case 9:
704
708
  {
705
709
  long long millis;
706
- VALUE seconds, microseconds;
707
710
  memcpy(&millis, buffer + *position, 8);
708
- seconds = LL2NUM(millis / 1000);
709
- microseconds = INT2NUM((millis % 1000) * 1000);
710
711
 
711
- value = rb_funcall(Time, rb_intern("at"), 2, seconds, microseconds);
712
+ value = rb_time_new(millis / 1000, (millis % 1000) * 1000);
712
713
  value = rb_funcall(value, rb_intern("utc"), 0);
713
714
  *position += 8;
714
715
  break;
@@ -756,7 +757,7 @@ static VALUE get_value(const char* buffer, int* position, int type) {
756
757
 
757
758
  str = rb_str_new(buffer + *position, 12);
758
759
  oid = rb_funcall(str, rb_intern("unpack"), 1, rb_str_new2("C*"));
759
- id = rb_class_new_instance(1, &oid, ObjectID);
760
+ id = rb_class_new_instance(1, &oid, ObjectId);
760
761
  *position += 12;
761
762
 
762
763
  argv[0] = collection;
@@ -909,13 +910,14 @@ static VALUE objectid_generate(VALUE self)
909
910
 
910
911
  void Init_cbson() {
911
912
  VALUE bson, CBson, Digest, ext_version;
912
- Time = rb_const_get(rb_cObject, rb_intern("Time"));
913
913
 
914
914
  bson = rb_const_get(rb_cObject, rb_intern("BSON"));
915
915
  rb_require("bson/types/binary");
916
916
  Binary = rb_const_get(bson, rb_intern("Binary"));
917
917
  rb_require("bson/types/objectid");
918
918
  ObjectID = rb_const_get(bson, rb_intern("ObjectID"));
919
+ rb_require("bson/types/object_id");
920
+ ObjectId = rb_const_get(bson, rb_intern("ObjectId"));
919
921
  rb_require("bson/types/dbref");
920
922
  DBRef = rb_const_get(bson, rb_intern("DBRef"));
921
923
  rb_require("bson/types/code");
@@ -942,6 +944,7 @@ void Init_cbson() {
942
944
  DigestMD5 = rb_const_get(Digest, rb_intern("MD5"));
943
945
 
944
946
  rb_define_method(ObjectID, "generate", objectid_generate, 0);
947
+ rb_define_method(ObjectId, "generate", objectid_generate, 0);
945
948
 
946
949
  rb_define_method(rb_cArray, "fast_pack", fast_pack, 0);
947
950
  }
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- #define VERSION "1.0.4"
17
+ #define VERSION "1.0.5"
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson_ext
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 29
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
8
  - 0
8
- - 4
9
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
10
11
  platform: ruby
11
12
  authors:
12
13
  - Mike Dirolf
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-13 00:00:00 -04:00
18
+ date: 2010-08-27 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -47,23 +48,27 @@ rdoc_options: []
47
48
  require_paths:
48
49
  - ext
49
50
  required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
50
52
  requirements:
51
53
  - - ">="
52
54
  - !ruby/object:Gem::Version
55
+ hash: 3
53
56
  segments:
54
57
  - 0
55
58
  version: "0"
56
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
57
61
  requirements:
58
62
  - - ">="
59
63
  - !ruby/object:Gem::Version
64
+ hash: 3
60
65
  segments:
61
66
  - 0
62
67
  version: "0"
63
68
  requirements: []
64
69
 
65
70
  rubyforge_project:
66
- rubygems_version: 1.3.6
71
+ rubygems_version: 1.3.7
67
72
  signing_key:
68
73
  specification_version: 3
69
74
  summary: C extensions for Ruby BSON.