kbaum-mongo 0.18.3p

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.
Files changed (72) hide show
  1. data/LICENSE.txt +202 -0
  2. data/README.rdoc +339 -0
  3. data/Rakefile +138 -0
  4. data/bin/bson_benchmark.rb +59 -0
  5. data/bin/fail_if_no_c.rb +11 -0
  6. data/examples/admin.rb +42 -0
  7. data/examples/capped.rb +22 -0
  8. data/examples/cursor.rb +48 -0
  9. data/examples/gridfs.rb +88 -0
  10. data/examples/index_test.rb +126 -0
  11. data/examples/info.rb +31 -0
  12. data/examples/queries.rb +70 -0
  13. data/examples/simple.rb +24 -0
  14. data/examples/strict.rb +35 -0
  15. data/examples/types.rb +36 -0
  16. data/lib/mongo/collection.rb +609 -0
  17. data/lib/mongo/connection.rb +672 -0
  18. data/lib/mongo/cursor.rb +403 -0
  19. data/lib/mongo/db.rb +555 -0
  20. data/lib/mongo/exceptions.rb +66 -0
  21. data/lib/mongo/gridfs/chunk.rb +91 -0
  22. data/lib/mongo/gridfs/grid.rb +79 -0
  23. data/lib/mongo/gridfs/grid_file_system.rb +101 -0
  24. data/lib/mongo/gridfs/grid_io.rb +338 -0
  25. data/lib/mongo/gridfs/grid_store.rb +580 -0
  26. data/lib/mongo/gridfs.rb +25 -0
  27. data/lib/mongo/types/binary.rb +52 -0
  28. data/lib/mongo/types/code.rb +36 -0
  29. data/lib/mongo/types/dbref.rb +40 -0
  30. data/lib/mongo/types/min_max_keys.rb +58 -0
  31. data/lib/mongo/types/objectid.rb +180 -0
  32. data/lib/mongo/types/regexp_of_holding.rb +45 -0
  33. data/lib/mongo/util/bson_c.rb +18 -0
  34. data/lib/mongo/util/bson_ruby.rb +606 -0
  35. data/lib/mongo/util/byte_buffer.rb +222 -0
  36. data/lib/mongo/util/conversions.rb +87 -0
  37. data/lib/mongo/util/ordered_hash.rb +140 -0
  38. data/lib/mongo/util/server_version.rb +69 -0
  39. data/lib/mongo/util/support.rb +26 -0
  40. data/lib/mongo.rb +63 -0
  41. data/mongo-ruby-driver.gemspec +28 -0
  42. data/test/auxillary/autoreconnect_test.rb +42 -0
  43. data/test/binary_test.rb +15 -0
  44. data/test/bson_test.rb +427 -0
  45. data/test/byte_buffer_test.rb +81 -0
  46. data/test/chunk_test.rb +82 -0
  47. data/test/collection_test.rb +515 -0
  48. data/test/connection_test.rb +160 -0
  49. data/test/conversions_test.rb +120 -0
  50. data/test/cursor_test.rb +379 -0
  51. data/test/db_api_test.rb +780 -0
  52. data/test/db_connection_test.rb +16 -0
  53. data/test/db_test.rb +272 -0
  54. data/test/grid_file_system_test.rb +210 -0
  55. data/test/grid_io_test.rb +78 -0
  56. data/test/grid_store_test.rb +334 -0
  57. data/test/grid_test.rb +87 -0
  58. data/test/objectid_test.rb +125 -0
  59. data/test/ordered_hash_test.rb +172 -0
  60. data/test/replica/count_test.rb +34 -0
  61. data/test/replica/insert_test.rb +50 -0
  62. data/test/replica/pooled_insert_test.rb +54 -0
  63. data/test/replica/query_test.rb +39 -0
  64. data/test/slave_connection_test.rb +36 -0
  65. data/test/test_helper.rb +42 -0
  66. data/test/threading/test_threading_large_pool.rb +90 -0
  67. data/test/threading_test.rb +87 -0
  68. data/test/unit/collection_test.rb +61 -0
  69. data/test/unit/connection_test.rb +117 -0
  70. data/test/unit/cursor_test.rb +93 -0
  71. data/test/unit/db_test.rb +98 -0
  72. metadata +127 -0
@@ -0,0 +1,222 @@
1
+ # --
2
+ # Copyright (C) 2008-2010 10gen Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ # A byte buffer.
18
+ class ByteBuffer
19
+
20
+ # Commonly-used integers.
21
+ INT_LOOKUP = {
22
+ 0 => [0, 0, 0, 0],
23
+ 1 => [1, 0, 0, 0],
24
+ 2 => [2, 0, 0, 0],
25
+ 3 => [3, 0, 0, 0],
26
+ 4 => [4, 0, 0, 0],
27
+ 2001 => [209, 7, 0, 0],
28
+ 2002 => [210, 7, 0, 0],
29
+ 2004 => [212, 7, 0, 0],
30
+ 2005 => [213, 7, 0, 0],
31
+ 2006 => [214, 7, 0, 0]
32
+ }
33
+
34
+ attr_reader :order
35
+
36
+ def initialize(initial_data=[])
37
+ @buf = initial_data
38
+ @cursor = @buf.length
39
+ @order = :little_endian
40
+ @int_pack_order = 'V'
41
+ @double_pack_order = 'E'
42
+ end
43
+
44
+ if RUBY_VERSION >= '1.9'
45
+ def self.to_utf8(str)
46
+ str.encode("utf-8")
47
+ end
48
+ else
49
+ def self.to_utf8(str)
50
+ begin
51
+ str.unpack("U*")
52
+ rescue => ex
53
+ raise InvalidStringEncoding, "String not valid utf-8: #{str}"
54
+ end
55
+ str
56
+ end
57
+ end
58
+
59
+ def self.serialize_cstr(buf, val)
60
+ buf.put_array(to_utf8(val.to_s).unpack("C*") + [0])
61
+ end
62
+
63
+ # +endianness+ should be :little_endian or :big_endian. Default is :little_endian
64
+ def order=(endianness)
65
+ @order = endianness
66
+ @int_pack_order = endianness == :little_endian ? 'V' : 'N'
67
+ @double_pack_order = endianness == :little_endian ? 'E' : 'G'
68
+ end
69
+
70
+ def rewind
71
+ @cursor = 0
72
+ end
73
+
74
+ def position
75
+ @cursor
76
+ end
77
+
78
+ def position=(val)
79
+ @cursor = val
80
+ end
81
+
82
+ def clear
83
+ @buf = []
84
+ rewind
85
+ end
86
+
87
+ def size
88
+ @buf.size
89
+ end
90
+ alias_method :length, :size
91
+
92
+ # Appends a second ByteBuffer object, +buffer+, to the current buffer.
93
+ def append!(buffer)
94
+ @buf = @buf + buffer.to_a
95
+ self
96
+ end
97
+
98
+ # Prepends a second ByteBuffer object, +buffer+, to the current buffer.
99
+ def prepend!(buffer)
100
+ @buf = buffer.to_a + @buf
101
+ self
102
+ end
103
+
104
+ def put(byte, offset=nil)
105
+ @cursor = offset if offset
106
+ @buf[@cursor] = byte
107
+ @cursor += 1
108
+ end
109
+
110
+ def put_array(array, offset=nil)
111
+ @cursor = offset if offset
112
+ @buf[@cursor, array.length] = array
113
+ @cursor += array.length
114
+ end
115
+
116
+ def put_int(i, offset=nil)
117
+ unless a = INT_LOOKUP[i]
118
+ a = []
119
+ [i].pack(@int_pack_order).each_byte { |b| a << b }
120
+ end
121
+ put_array(a, offset)
122
+ end
123
+
124
+ def put_long(i, offset=nil)
125
+ offset = @cursor unless offset
126
+ if @int_pack_order == 'N'
127
+ put_int(i >> 32, offset)
128
+ put_int(i & 0xffffffff, offset + 4)
129
+ else
130
+ put_int(i & 0xffffffff, offset)
131
+ put_int(i >> 32, offset + 4)
132
+ end
133
+ end
134
+
135
+ def put_double(d, offset=nil)
136
+ a = []
137
+ [d].pack(@double_pack_order).each_byte { |b| a << b }
138
+ put_array(a, offset)
139
+ end
140
+
141
+ # If +size+ == nil, returns one byte. Else returns array of bytes of length
142
+ # # +size+.
143
+ def get(len=nil)
144
+ one_byte = len.nil?
145
+ len ||= 1
146
+ check_read_length(len)
147
+ start = @cursor
148
+ @cursor += len
149
+ if one_byte
150
+ @buf[start]
151
+ else
152
+ if @buf.respond_to? "unpack"
153
+ @buf[start, len].unpack("C*")
154
+ else
155
+ @buf[start, len]
156
+ end
157
+ end
158
+ end
159
+
160
+ def get_int
161
+ check_read_length(4)
162
+ vals = ""
163
+ (@cursor..@cursor+3).each { |i| vals << @buf[i].chr }
164
+ @cursor += 4
165
+ vals.unpack(@int_pack_order)[0]
166
+ end
167
+
168
+ def get_long
169
+ i1 = get_int
170
+ i2 = get_int
171
+ if @int_pack_order == 'N'
172
+ (i1 << 32) + i2
173
+ else
174
+ (i2 << 32) + i1
175
+ end
176
+ end
177
+
178
+ def get_double
179
+ check_read_length(8)
180
+ vals = ""
181
+ (@cursor..@cursor+7).each { |i| vals << @buf[i].chr }
182
+ @cursor += 8
183
+ vals.unpack(@double_pack_order)[0]
184
+ end
185
+
186
+ def more?
187
+ @cursor < @buf.size
188
+ end
189
+
190
+ def to_a
191
+ if @buf.respond_to? "unpack"
192
+ @buf.unpack("C*")
193
+ else
194
+ @buf
195
+ end
196
+ end
197
+
198
+ def unpack(args)
199
+ to_a
200
+ end
201
+
202
+ def to_s
203
+ if @buf.respond_to? :fast_pack
204
+ @buf.fast_pack
205
+ elsif @buf.respond_to? "pack"
206
+ @buf.pack("C*")
207
+ else
208
+ @buf
209
+ end
210
+ end
211
+
212
+ def dump
213
+ @buf.each_with_index { |c, i| $stderr.puts "#{'%04d' % i}: #{'%02x' % c} #{'%03o' % c} #{'%s' % c.chr} #{'%3d' % c}" }
214
+ end
215
+
216
+ private
217
+
218
+ def check_read_length(len)
219
+ raise "attempt to read past end of buffer" if @cursor + len > @buf.length
220
+ end
221
+
222
+ end
@@ -0,0 +1,87 @@
1
+ # --
2
+ # Copyright (C) 2008-2010 10gen Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+ module Mongo #:nodoc:
17
+
18
+ # Utility module to include when needing to convert certain types of
19
+ # objects to mongo-friendly parameters.
20
+ module Conversions
21
+
22
+ ASCENDING_CONVERSION = ["ascending", "asc", "1"]
23
+ DESCENDING_CONVERSION = ["descending", "desc", "-1"]
24
+
25
+ # Converts the supplied +Array+ to a +Hash+ to pass to mongo as
26
+ # sorting parameters. The returned +Hash+ will vary depending
27
+ # on whether the passed +Array+ is one or two dimensional.
28
+ #
29
+ # Example:
30
+ #
31
+ # <tt>array_as_sort_parameters([["field1", :asc], ["field2", :desc]])</tt> =>
32
+ # <tt>{ "field1" => 1, "field2" => -1}</tt>
33
+ def array_as_sort_parameters(value)
34
+ order_by = OrderedHash.new
35
+ if value.first.is_a? Array
36
+ value.each do |param|
37
+ if (param.class.name == "String")
38
+ order_by[param] = 1
39
+ else
40
+ order_by[param[0]] = sort_value(param[1]) unless param[1].nil?
41
+ end
42
+ end
43
+ elsif !value.empty?
44
+ if order_by.size == 1
45
+ order_by[value.first] = 1
46
+ else
47
+ order_by[value.first] = sort_value(value[1])
48
+ end
49
+ end
50
+ order_by
51
+ end
52
+
53
+ # Converts the supplied +String+ or +Symbol+ to a +Hash+ to pass to mongo as
54
+ # a sorting parameter with ascending order. If the +String+
55
+ # is empty then an empty +Hash+ will be returned.
56
+ #
57
+ # Example:
58
+ #
59
+ # *DEPRECATED
60
+ #
61
+ # <tt>string_as_sort_parameters("field")</tt> => <tt>{ "field" => 1 }</tt>
62
+ # <tt>string_as_sort_parameters("")</tt> => <tt>{}</tt>
63
+ def string_as_sort_parameters(value)
64
+ return {} if (str = value.to_s).empty?
65
+ { str => 1 }
66
+ end
67
+
68
+ # Converts the +String+, +Symbol+, or +Integer+ to the
69
+ # corresponding sort value in MongoDB.
70
+ #
71
+ # Valid conversions (case-insensitive):
72
+ #
73
+ # <tt>ascending, asc, :ascending, :asc, 1</tt> => <tt>1</tt>
74
+ # <tt>descending, desc, :descending, :desc, -1</tt> => <tt>-1</tt>
75
+ #
76
+ # If the value is invalid then an error will be raised.
77
+ def sort_value(value)
78
+ val = value.to_s.downcase
79
+ return 1 if ASCENDING_CONVERSION.include?(val)
80
+ return -1 if DESCENDING_CONVERSION.include?(val)
81
+ raise InvalidSortValueError.new(
82
+ "#{self} was supplied as a sort direction when acceptable values are: " +
83
+ "Mongo::ASCENDING, 'ascending', 'asc', :ascending, :asc, 1, Mongo::DESCENDING, " +
84
+ "'descending', 'desc', :descending, :desc, -1.")
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,140 @@
1
+ # --
2
+ # Copyright (C) 2008-2010 10gen Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ # A hash in which the order of keys are preserved.
18
+ #
19
+ # Under Ruby 1.9 and greater, this class has no added methods because Ruby's
20
+ # Hash already keeps its keys ordered by order of insertion.
21
+ class OrderedHash < Hash
22
+
23
+ def ==(other)
24
+ begin
25
+ !other.nil? &&
26
+ keys == other.keys &&
27
+ values == other.values
28
+ rescue
29
+ false
30
+ end
31
+ end
32
+
33
+ # We only need the body of this class if the RUBY_VERSION is before 1.9
34
+ if RUBY_VERSION < '1.9'
35
+ attr_accessor :ordered_keys
36
+
37
+ def self.[] *args
38
+ oh = OrderedHash.new
39
+ if Hash === args[0]
40
+ oh.merge! args[0]
41
+ elsif (args.size % 2) != 0
42
+ raise ArgumentError, "odd number of elements for Hash"
43
+ else
44
+ 0.step(args.size - 1, 2) do |key|
45
+ value = key + 1
46
+ oh[args[key]] = args[value]
47
+ end
48
+ end
49
+ oh
50
+ end
51
+
52
+ def initialize(*a, &b)
53
+ super
54
+ @ordered_keys = []
55
+ end
56
+
57
+ def keys
58
+ @ordered_keys || []
59
+ end
60
+
61
+ def []=(key, value)
62
+ @ordered_keys ||= []
63
+ @ordered_keys << key unless @ordered_keys.include?(key)
64
+ super(key, value)
65
+ end
66
+
67
+ def each
68
+ @ordered_keys ||= []
69
+ @ordered_keys.each { |k| yield k, self[k] }
70
+ self
71
+ end
72
+ alias :each_pair :each
73
+
74
+ def to_a
75
+ @ordered_keys ||= []
76
+ @ordered_keys.map { |k| [k, self[k]] }
77
+ end
78
+
79
+ def values
80
+ collect { |k, v| v }
81
+ end
82
+
83
+ def merge(other)
84
+ oh = self.dup
85
+ oh.merge!(other)
86
+ oh
87
+ end
88
+
89
+ def merge!(other)
90
+ @ordered_keys ||= []
91
+ @ordered_keys += other.keys # unordered if not an OrderedHash
92
+ @ordered_keys.uniq!
93
+ super(other)
94
+ end
95
+
96
+ alias :update :merge!
97
+
98
+ def inspect
99
+ str = '{'
100
+ str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
101
+ str << '}'
102
+ end
103
+
104
+ def delete(key, &block)
105
+ @ordered_keys.delete(key) if @ordered_keys
106
+ super
107
+ end
108
+
109
+ def delete_if(&block)
110
+ self.each { |k,v|
111
+ if yield k, v
112
+ delete(k)
113
+ end
114
+ }
115
+ end
116
+
117
+ def clear
118
+ super
119
+ @ordered_keys = []
120
+ end
121
+
122
+ def hash
123
+ code = 17
124
+ each_pair do |key, value|
125
+ code = 37 * code + key.hash
126
+ code = 37 * code + value.hash
127
+ end
128
+ code & 0x7fffffff
129
+ end
130
+
131
+ def eql?(o)
132
+ if o.instance_of? OrderedHash
133
+ self.hash == o.hash
134
+ else
135
+ false
136
+ end
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,69 @@
1
+ # --
2
+ # Copyright (C) 2008-2010 10gen Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+ module Mongo
17
+ # Simple class for comparing server versions.
18
+ class ServerVersion
19
+ include Comparable
20
+
21
+ def initialize(version)
22
+ @version = version
23
+ end
24
+
25
+ # Implements comparable.
26
+ def <=>(new)
27
+ local, new = self.to_a, to_array(new)
28
+ for n in 0...local.size do
29
+ break if elements_include_mods?(local[n], new[n])
30
+ if local[n] < new[n].to_i
31
+ result = -1
32
+ break;
33
+ elsif local[n] > new[n].to_i
34
+ result = 1
35
+ break;
36
+ end
37
+ end
38
+ result || 0
39
+ end
40
+
41
+ # Return an array representation of this server version.
42
+ def to_a
43
+ to_array(@version)
44
+ end
45
+
46
+ # Return a string representation of this server version.
47
+ def to_s
48
+ @version
49
+ end
50
+
51
+ private
52
+
53
+ # Returns true if any elements include mod symbols (-, +)
54
+ def elements_include_mods?(*elements)
55
+ elements.any? { |n| n =~ /[\-\+]/ }
56
+ end
57
+
58
+ # Converts argument to an array of integers,
59
+ # appending any mods as the final element.
60
+ def to_array(version)
61
+ array = version.split(".").map {|n| (n =~ /^\d+$/) ? n.to_i : n }
62
+ if array.last =~ /(\d+)([\-\+])/
63
+ array[array.length-1] = $1.to_i
64
+ array << $2
65
+ end
66
+ array
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,26 @@
1
+ # --
2
+ # Copyright (C) 2008-2010 10gen Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ++
16
+
17
+ #:nodoc:
18
+ class Object
19
+
20
+ #:nodoc:
21
+ def returning(value)
22
+ yield value
23
+ value
24
+ end
25
+
26
+ end
data/lib/mongo.rb ADDED
@@ -0,0 +1,63 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ module Mongo
4
+ VERSION = "0.18.3p"
5
+ end
6
+
7
+ begin
8
+ # Need this for running test with and without c ext in Ruby 1.9.
9
+ raise LoadError if ENV['TEST_MODE'] && !ENV['C_EXT']
10
+ require 'mongo_ext/cbson'
11
+ raise LoadError unless defined?(CBson::VERSION) && CBson::VERSION == Mongo::VERSION
12
+ require 'mongo/util/bson_c'
13
+ BSON = BSON_C
14
+ rescue LoadError
15
+ require 'mongo/util/bson_ruby'
16
+ BSON = BSON_RUBY
17
+ warn "\n**Notice: C extension not loaded. This is required for optimum MongoDB Ruby driver performance."
18
+ warn " You can install the extension as follows:\n gem install mongo_ext\n"
19
+ warn " If you continue to receive this message after installing, make sure that the"
20
+ warn " mongo_ext gem is in your load path and that the mongo_ext and mongo gems are of the same version.\n"
21
+ end
22
+
23
+ module Mongo
24
+ ASCENDING = 1
25
+ DESCENDING = -1
26
+
27
+ module Constants
28
+ OP_REPLY = 1
29
+ OP_MSG = 1000
30
+ OP_UPDATE = 2001
31
+ OP_INSERT = 2002
32
+ OP_QUERY = 2004
33
+ OP_GET_MORE = 2005
34
+ OP_DELETE = 2006
35
+ OP_KILL_CURSORS = 2007
36
+
37
+ OP_QUERY_SLAVE_OK = 4
38
+ OP_QUERY_NO_CURSOR_TIMEOUT = 16
39
+ end
40
+
41
+ end
42
+
43
+ require 'mongo/types/binary'
44
+ require 'mongo/types/code'
45
+ require 'mongo/types/dbref'
46
+ require 'mongo/types/objectid'
47
+ require 'mongo/types/regexp_of_holding'
48
+ require 'mongo/types/min_max_keys'
49
+
50
+ require 'mongo/util/support'
51
+ require 'mongo/util/conversions'
52
+ require 'mongo/util/server_version'
53
+ require 'mongo/util/bson_ruby'
54
+
55
+ require 'mongo/collection'
56
+ require 'mongo/connection'
57
+ require 'mongo/cursor'
58
+ require 'mongo/db'
59
+ require 'mongo/exceptions'
60
+ require 'mongo/gridfs'
61
+ require 'mongo/gridfs/grid'
62
+ require 'mongo/gridfs/grid_io'
63
+ require 'mongo/gridfs/grid_file_system'
@@ -0,0 +1,28 @@
1
+ require "lib/mongo"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'kbaum-mongo'
5
+
6
+ s.version = Mongo::VERSION
7
+
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = 'Ruby driver for the MongoDB'
10
+ s.description = 'A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.'
11
+
12
+ s.require_paths = ['lib']
13
+
14
+ s.files = ['README.rdoc', 'Rakefile', 'mongo-ruby-driver.gemspec', 'LICENSE.txt']
15
+ s.files += Dir['lib/**/*.rb'] + Dir['examples/**/*.rb'] + Dir['bin/**/*.rb']
16
+ s.test_files = Dir['test/**/*.rb']
17
+
18
+ s.has_rdoc = true
19
+ s.test_files = Dir['test/**/*.rb']
20
+
21
+ s.has_rdoc = true
22
+ s.rdoc_options = ['--main', 'README.rdoc', '--inline-source']
23
+ s.extra_rdoc_files = ['README.rdoc']
24
+
25
+ s.authors = ['Jim Menard', 'Mike Dirolf']
26
+ s.email = 'mongodb-dev@googlegroups.com'
27
+ s.homepage = 'http://www.mongodb.org'
28
+ end
@@ -0,0 +1,42 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'mongo'
3
+ require 'test/unit'
4
+ require 'test/test_helper'
5
+
6
+ # NOTE: This test requires bouncing the server
7
+ class AutoreconnectTest < Test::Unit::TestCase
8
+ include Mongo
9
+
10
+ def setup
11
+ @conn = Mongo::Connection.new
12
+ @db = @conn.db('mongo-ruby-test')
13
+ @db.drop_collection("test-connect")
14
+ @coll = @db.collection("test-connect")
15
+ end
16
+
17
+ def test_query
18
+ @coll.save({:a => 20})
19
+ @coll.save({:a => 30})
20
+ @coll.save({:a => 40})
21
+ results = []
22
+ @coll.find.each {|r| results << r}
23
+ [20, 30, 40].each do |a|
24
+ assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
25
+ end
26
+
27
+ puts "Please disconnect and then reconnect the current master."
28
+ gets
29
+
30
+ begin
31
+ @coll.find.to_a
32
+ rescue Mongo::ConnectionFailure
33
+ end
34
+
35
+ results = []
36
+ @coll.find.each {|r| results << r}
37
+ [20, 30, 40].each do |a|
38
+ assert results.any? {|r| r['a'] == a}, "Could not find record for a => #{a}"
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,15 @@
1
+ # encoding:utf-8
2
+ require 'test/test_helper'
3
+
4
+ class BinaryTest < Test::Unit::TestCase
5
+ context "Inspecting" do
6
+ setup do
7
+ @data = ("THIS IS BINARY " * 50).unpack("c*")
8
+ end
9
+
10
+ should "not display actual data" do
11
+ binary = Mongo::Binary.new(@data)
12
+ assert_equal "<Mongo::Binary:#{binary.object_id}>", binary.inspect
13
+ end
14
+ end
15
+ end